Using subdomains to speed up your site

14 October 2009| 7 Comments| Print

The average web page contains over 50 elements each of which has to be downloaded from a web server. The HTTP 1.1 specifications recommend that a web browser or server should only typically make two simultaneous downloads per domain or hostname. So most web browsers are effectively restricted by this limit on parallel downloads if the objects in the web page they download are hosted on one server. However there are two ways around this limitation:

  1. You can serve your page elements from multiple servers each with a different ip address or hostname
  2. Or create multiple subdomains to serve your content from

the second option is a more elegant solution which requires you to set up multiple subdomains that point to the same server. This technique fools web browsers into believing the page elements are being served from different hostnames, thereby allowing more than two-threads per server. For example you can set:

  • images1.yourdomain.com
  • images2.yourdomain.com
  • images3.yourdomain.com
  • images4.yourdomain.com
  • images5.yourdomain.com

Anything simpler?

But fear not, there is a quick and easy solution that you can do with just HTML and CSS. Use Image Sprites. This reduces the number of image requests to the server. Combine all the images in your page into a single image and use the CSS background-image and background-position properties to display the desired image segment. Its very useful and used on big sites such as MySpace and Mashable.


Share:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • DZone
  • Reddit
  • Netvibes

7 Comments

  • Eire32

    This is a good point that I have been meaning to do for ages on my own sites. One thing I would say is you need to find the balance between loading of different domains to allow more parallel downloads and DNS Lookup. I can’t remember the suggested about exactly but to the best of my knowledge Google suggest using at max 4 host names and I think Yahoo! suggest only 3 (that includes you example.com domain). Speeding up you site is always such a balancing act, but google have some good tricks and so do Yahoo! Great article I liked it, to the point, short and sweet.

    Eire.32

  • Brian Johnson

    Ahh, this is very interesting. I do put static files on other subdomains because it makes things more organized (Woops American spelling :-o ) and because it looks cool! But I didn’t know it had a purpose lol! Awesome post my friend. How is dotdashcreate going these days?

  • Ashley

    @Brian, Ha thanks for that, yeah you learn something new everyday ;) Yeah DDC’s currently on hold i’m currently working on some big projects at the moment.

  • Maicon Sobczak

    Very useful tip! For sure that I will use this and tweet.

  • Ken

    Hello Ashley,

    Been looking at this technique in the past few days and found your site. Of course there are people against it and others like you that recommended.

    I personally would love to try it but, forgive my ignorance. I’ve created the subdomain added the static files like css, javascript, etc.

    But is that enough? Do I need to do redirects, create a special htaccess file?

    For what is worth I am on a shared hosting account. I also tried doing the same via a plugin called w3 total cache but couldn’t get it to work or communicate properly in their cdn settings.

    Thanks in advance for your input.

    -Ken

  • Ashley

    @ Ken, I don’t think there’s any need to add a .htaccess file, thats not to say you shouldn’t, you could re-direct users that visit your sub-domain root to your site.

    It’s only really worth using sub domains if your getting tens of thousands of visits a day for a site with less than this there is little point.

    Hope that helps!

  • Ken

    Hello Ashley,

    Thanks for your reply. As it turns out with the ongoing world cup I am getting hammered or so I think with about 25 to 30 thousand visits a day.

    I also anticipate that the flow of traffic will only be temporarily but never the less I want visitors to have a great experience.

    So with that in mind do you added any other special setup to your technique, could you elaborate a bit more on the process of setting the subdomain, moving the files, linking them, any dns settings that you might have used.

    Thanks very much.

Leave a comment...

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled site. To get your own globally-recognized-avatar, register at Gravatar.

Your Ad Here