同时存在太多多个 AJAX 连接是否不好?

发布于 2024-10-03 18:51:10 字数 291 浏览 3 评论 0原文

我正在编写一个相当大的基于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月静好 2024-10-10 18:51:10

IE6 并不是您唯一的问题;其他浏览器也会限制对同一服务器的并发请求数量。 这是一个很好的综述,它说截至撰写本文时,默认值是:

Browser           HTTP/1.1    HTTP/1.0
-------           --------    --------
IE 6,7            2           4
IE 8              6           6
Firefox 2         2           8
Firefox 3         6           6
Safari 3,4        4           4
Chrome 1,2        6           ?
Chrome 3          4           4
Opera 9.63        4           4
Opera 10.00alpha  4           4

除此之外,该文章中的另外两个重要引用:

可以重新配置您的浏览器以使用不同的限制。

请注意,对于拨号连接的用户,IE8 会自动将每个服务器的连接数减少到 2 个。

...据您所知,其他现代浏览器会这样做,或者可能会在下一个“点”版本中开始这样做。

如果可以的话,一定要尽量将长期打开的连接数量保持在最低限度。当然,不要主动长时间保持多个连接打开。

如果您只是进行大量单独的快速连接,有时它们会聚集在一起,那么您可能想自己序列化它们,而不是依赖浏览器来完成。有一个表示需要完成的请求的对象队列,以及负责执行这些请求的代码(一次一个)。

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:

Browser           HTTP/1.1    HTTP/1.0
-------           --------    --------
IE 6,7            2           4
IE 8              6           6
Firefox 2         2           8
Firefox 3         6           6
Safari 3,4        4           4
Chrome 1,2        6           ?
Chrome 3          4           4
Opera 9.63        4           4
Opera 10.00alpha  4           4

Aside from that, two other important quotes from that article:

It’s possible to reconfigure your browser to use different limits.

and

Note that IE8 automatically drops back to 2 connections per server for users on dialup connections.

...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).

怀里藏娇 2024-10-10 18:51:10

太多总是不好的。

阅读本文了解有关 AJAX 优化的更多信息。

too many is always bad.

Read more about AJAX optimization in this article.

绝情姑娘 2024-10-10 18:51:10

根据上面答案中列出的浏览器,是的。在某些情况下,如果它们没有按时间顺序排队发送请求,您可能会发现在某些情况下,某些返回信息可能会混淆并显示在错误的元素中,以加载 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文