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.
6 thoughts on “2 reasons you should host all static content on a different domain”
Thank you very much for this very interesting detail about optimizing webserver performance.
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.
Thanks for the compliments, making simple and useful websites has been my hobby. 🙂
You explained this very clearly, in fact, I used it to persuade my boss to give a hosting budget – we self host atm.
Comments are closed.