Code: The Two-connection limit

Chapter 8 - Ajax Optimization

The reality of the two-connection limit is the primary reason why people host images or other dependent objects such as JavaScript and CSS files on other domains. For example, the site Example.com serving an HTML page containing the following image references:

<img src="image1.gif" />
<img src="image2.gif" />
<img src="image3.gif" />
<img src="image4.gif" />

would find that using other fully qualified domain names such as those shown here will increase the fetching browser’s connection efficiency:

<img src="http://images.example.com/image1.gif" />
<img src="http://images.example.com/image2.gif" />
<img src="http://images2.example.com/image3.gif" />
<img src="http://images2.example.com/image4.gif" />

Your Ajax programs can make only two connections at a time, so if you make a third or fourth request, it will have to wait until one of the other requests finishes. Now, this can be quite problematic if your requests stall for some reason. You will find that your connection will then choke.

Given the previous discussion of utilizing additional domains to increase image request parallelization, you might be tempted to use the same trick here, but it will not work. You see, Ajax falls under the security policy known as the Same-Origin Policy (Same origin policy Wikipedia), which limits you to making requests from the same domain name that served the page. So to minimize the impact of HTTP request bundle your scripts together and group requests.

References

We have done extensive testing on this default.
There are ways to modify it in the browser, but by default, two is the limit of simultaneous connections, at least for JavaScript files. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html for more details.