同时发送 XMLHttpRequest
我正在编写一个 Google Chrome 扩展程序,它可以查找 这个 然后发送请求到myanimelist.net 获取标题的评级。然后将评级插入到页面中。
一个页面包含大约 100 个标题,因此该扩展需要执行 100 个 HTTP 请求。是否可以一次执行所有 100 个请求,还是应该等到一个请求完成后再发送下一个请求?
有没有办法缓存结果,以便在刷新页面时不需要重做请求?
I'm writing a Google Chrome extension that finds all titles on pages like this one and then sends a request to myanimelist.net to get the title's rating. The ratings are then inserted into the page.
A page contains about 100 titles, so the extension needs to perform 100 HTTP requests. Is it OK to do all 100 requests at once, or should I wait until one request is completed before sending the next one?
Is there a way to cache the results so that I don't need to redo the requests if the page is refreshed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您一次运行 100 个请求,目标服务器可能会阻止您,具体取决于其设置。我宁愿小批量发送请求,比如一次发送 5 个请求。
如果您需要在浏览器重新启动之间保持持久性,则可以将结果缓存在
localStorage
中;如果不需要,则可以将结果缓存在后台页面变量空间中。If you run 100 requests at once a destination server might block you, depending on its settings. I would rather send requests in small batches, like 5 at once.
You can cache results in
localStorage
if you need persistence between browser restarts, or just in a background page variable space, if you don't.