Is having too many multiple simultaneous AJAX connections bad?

10,332

Solution 1

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

Solution 2

too many is always bad.

Read more about AJAX optimization in this article.

Solution 3

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.

Share:
10,332
Tower
Author by

Tower

Updated on July 22, 2022

Comments

  • Tower
    Tower almost 2 years

    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.

  • Tower
    Tower over 13 years
    Yes, limiting the amount of connections is always going to happen, but IE6 literally kills your AJAX requests if you do too many of them unlike newer browsers which make the requests just wait.
  • Tower
    Tower over 13 years
    So, are you suggesting that I should implement a pool that, say, requests after fourth to be "pending" and continue after other finishes?
  • T.J. Crowder
    T.J. Crowder over 13 years
    @rFactor: Not a pool, a queue, unless you're really reusing open connections Comet-style. And I would probably only allow a single outstanding request at a time (see my edit just now).
  • Alexis Wilke
    Alexis Wilke about 7 years
    You are correct. Your success() functions are called successively in the order replies are received and not in the order they were added. That can indeed look very strange.
  • MattOlivos
    MattOlivos about 7 years
    You can use jQuery Ajax load functions and they seem to work better at handling no matter the order.