Search code examples
javascriptajaxperformancenetwork-programmingxmlhttprequest

Is having too many multiple simultaneous AJAX connections bad?


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.


Solution

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