同时存在太多多个 AJAX 连接是否不好?
我正在编写一个相当大的基于 JavaScript 的应用程序,有时甚至会同时处理八 (8) 个 AJAX 请求。这是 IE6 中的一个问题,因为它会杀死其余的请求,我知道这一点,但这个应用程序是针对现代浏览器的,所以 IE6 不是问题。
然而,我有一种感觉(没有进行任何实际的分析),池化请求可以带来更好的性能。比如说,一次最多 4 个请求。
所以,我的问题是,汇集 AJAX 请求是否有任何好处,或者与拥有一个接一个处理请求的池相比,同时处理多个请求是否可以?
我意识到这可能取决于浏览器和互联网连接,但我对此不确定。
I am writing a rather large JavaScript based application and sometimes there are cases when it has even eight (8) AJAX requests going on at once. This is a problem in IE6, because it kills the rest of the requests, I know that, but this application is targeted for modern browsers, so, IE6 is not a problem.
However, I have a feeling (have not done any actual profiling) that pooling requests could yield in better performance. Say, maximum of 4 requests at a time.
So, my question is that is there any benefit to pool AJAX requests or is it okay to have multiple requests going on at the same time compared to having a pool where they are processed one after another?
I realize that this might depend on the browser and Internet connection, but I am not sure about that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
IE6 并不是您唯一的问题;其他浏览器也会限制对同一服务器的并发请求数量。 这是一个很好的综述,它说截至撰写本文时,默认值是:
除此之外,该文章中的另外两个重要引用:
和
...据您所知,其他现代浏览器会这样做,或者可能会在下一个“点”版本中开始这样做。
如果可以的话,一定要尽量将长期打开的连接数量保持在最低限度。当然,不要主动长时间保持多个连接打开。
如果您只是进行大量单独的快速连接,有时它们会聚集在一起,那么您可能想自己序列化它们,而不是依赖浏览器来完成。有一个表示需要完成的请求的对象队列,以及负责执行这些请求的代码(一次一个)。
IE6 isn't going to be your only problem; other browsers also limit the number of concurrent requests to the same server. Here's a good roundup, which says that as of that writing the defaults were:
Aside from that, two other important quotes from that article:
and
...and for all you know, other modern browsers do, or may start doing so with their next "dot" release.
If you can, definitely try to keep the number of long-standing open connections to a minimum. Certainly don't actively keep more than one connection open for a long time.
If you're just doing a lot of individual, quick connections and sometimes they bunch up, you probably want to serialize them yourself rather than relying on the browser to do it. Have a queue of objects representing the request that needs to be done, and code responsible for doing them (one at a time).
太多
总是不好的。阅读本文了解有关 AJAX 优化的更多信息。
too many
is always bad.Read more about AJAX optimization in this article.
根据上面答案中列出的浏览器,是的。在某些情况下,如果它们没有按时间顺序排队发送请求,您可能会发现在某些情况下,某些返回信息可能会混淆并显示在错误的元素中,以加载 ajax POST 请求返回信息。
Depending on the browsers listed in above answers, yes. In some cases if they are not queued to send a request in a chronological order you might find in certain scenarios where some returning information might get mixed up and show up in the wrong element looking to load an ajax POST request return information.