The Case for Registering Multiple Domains

Via /.Optimizing Page Load Time has some very interesting insight, in particular this point;

By default, IE allows only two outstanding connections per hostname when talking to HTTP/1.1 servers or eight-ish outstanding connections total. Firefox has similar limits. Using up to four hostnames instead of one will give you more connections. (IP addresses don’t matter; the hostnames can all point to the same IP.)

That’s actually an HTTP 1.1 recommendation (section 8.1.4);

Clients that use persistent connections SHOULD limit the number of
simultaneous connections that they maintain to a given server. A
single-user client SHOULD NOT maintain more than 2 connections with
any server or proxy. A proxy SHOULD use up to 2*N connections to
another server or proxy, where N is the number of simultaneously
active users. These guidelines are intended to improve HTTP response
times and avoid congestion.

More snippets of insight here and here. This is also something you should think about related to AJAX.

A minor nit: the approach recommended in “Optimizing Page Load Time” is;

Rather than loading all of your objects from http://static.example.com/, create four hostnames (e.g. static0.example.com, static1.example.com, static2.example.com, static3.example.com)

That may not be optimal solution though – if you’re using cookies with a domain like .mysite.com then clients will be sending cookies in their static content requests – that may miss the opportunity to have intermediary proxy servers cache for you, further distributing load / reducing network distances – described in Michael J. Radwin’s HTTP Caching & Cache-Busting for Content Publishers under “3. Cookie-free TLD for static content” (watch for speaker notes).

In other words, when you get to start worrying about this stuff, you probably want to think about registering a separate domain for static content, under which you can then employ subdomains to reduce page load time.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • http://www.realityedge.com.au mrsmiley

    Does the same theory apply for dynamic content as well? I know the cookie issue might be a hurdle if people are using them as session trackers.

    I must admit though, I did wonder why sites like eBay load images etc from another domain. Figured it was some some kind of consolidation excercise with PayPal.

    In the end, no matter how many connections the client opens to your infrastructure, they are still limited by their ISP connection. But I digress, that’s client performance vs server performance.

  • Ambush Commander

    Images loading from another domain has more to do with letting one server/domain be dedicated to serving static content, while the main server does server side processing.

  • TheAnarchist

    Where it says hostname here, do browsers consider subdomains to be seperate hostnames, or the same hostname?

  • http://www.phppatterns.com HarryF

    Does the same theory apply for dynamic content as well? I know the cookie issue might be a hurdle if people are using them as session trackers.

    Not sure I understand the question.

    Images loading from another domain has more to do with letting one server/domain be dedicated to serving static content, while the main server does server side processing.

    That’s a good point. Servers like TinyHTTPD often get employed to do this.

    A single Apache child + mod_php, for example, represents a significant block of memory – the principle is don’t waste those child processes on serving “dumb” content. And, specific to PHP, it can also be important when you’re using persistent resources that stay in memory – George Schlossnagle makes that point well here;

    If the average page in your Web application contains nine images, then only ten percent of the requests to your Web server actually used the persistent connections they have assigned to them. In other words, ninety percent of the requests are wasting a valuable (and expensive, from a scalability standpoint) Oracle connection handle. Your goal should be to ensure that only requests that require Oracle connectivity (or at least require dynamic content) are served off of your dynamic Web server. This will increase the amount of Oracle-related work done by each process, which in turn reduces the number of children required to generate dynamic content.

    The easiest way to promote this is by offloading all of your images onto a separate Web server (or set of Web servers).

  • http://www.phppatterns.com HarryF

    Where it says hostname here, do browsers consider subdomains to be seperate hostnames, or the same hostname?

    They should consider them to be seperate hostnames. The problem related to cookies though is if you have “.mydomain.com” as the cookie domain, the browser will send the cookie on each request to mydomain.com and all subdomains.

    Aside from how intermediate proxies respond to that, it can be a significant chunk of bandwidth you’re losing to those requests – if the cookie header is, say ~ 500 bytes (about the size of Sitepoint’s cookies), for a page that requires say 10 images, 1 external Javascript script and 1 CSS file, all on the same domain, that’s 6 kbytes of bandwidth spent, just on having cookies sent for static content requests – adds up when you have a lot of visitors.