2 reasons you should host all static content on a different domain

by Yang Yang on January 24, 2010

That is, to host all static content such as ready-made images, scripts, style sheets on a different domain rather than the primary one that hosts the page of the current URL. For example, if you intend to add static images to the web page located at http://www.example.com/page.html, you should not place the images on www.example.com, instead, put them somewhere else such as example-static.com or static.example.com.

The first reasoning for this is that browsers load web assets one by one or sequentially from a single host. They will not start requesting and downloading the next asset until they are finished with the previous one from the same domain. Therefore, doubling the hosts or domains can accelerate the downloading speed by about 100% because browsers can simultaneously download stuff from 2 different domains.

Another reasoning is that if cookie or session is enabled on your website, the browser would send the session cookie every time it makes a request to the domain, which sort of is useless because it’s static content – the server doesn’t need the cookie at all to serve static content such as images. It’s not only a waste of bandwidth but also a waste of communication time. To avoid this, serve all static content from a domain that is not cookie enabled. For instance, if you have set cookie with example.com, you can host all static content at static.example.com, however, if you have enabled cookie by *.example.com instead of just example.com, you will need to register a whole different domain to host the static content to steer clear of the useless overhead.

Not much for a small site, but this would be a major improvement regarding user experience for established, popular websites.

Robert Redl February 3, 2010 at 8:28 pm

Thank you very much for this very interesting detail about optimizing webserver performance.

Mr. Andrew February 10, 2010 at 10:09 pm

Yes, this is indeed very useful.
And much more of it, the website http://www.topclassicalmusic.com/ from which I arrived to Kavoir is delightful. So thank you for keeping a standard up for true value.


Yang Yang February 12, 2010 at 12:37 pm

Thanks for the compliments, making simple and useful websites has been my hobby. 🙂

Windows server admin musings February 11, 2011 at 11:14 pm

You explained this very clearly, in fact, I used it to persuade my boss to give a hosting budget – we self host atm.

Hossam November 14, 2012 at 8:40 pm

Thanks man

Comments on this entry are closed.

{ 1 trackback }

Previous post:

Next post: