Use your left/right keys to browse tutorials
Using subdomains to speed up your site

Using subdomains to speed up your site

1 Star2 Stars3 Stars4 Stars5 Stars
Posted on October 14, 2009

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.


Recent shares

More tutorials from Papermashup
Comments
9 discussions around Using subdomains to speed up your site
  1. Not a bad article at all. I have been looking into these approaches recently, and have been umming and ahhing a lot. There’s a lot of talk about using proper CDN’s, but I never knew about using the same server as the one the website is hosted on. I thought browsers would know about that.

    As you said, there is a fine line between speeding up your site and unnecessary work. I’ll have a think about it. At the moment I think we’re getting less than 100 visits per day. Do you reckon it’s pointless?

  2. Jobst says:

    I have been tossing around the idea of implementing subdomains on my site, and your article is compelling. If it speeds up the site, enhances user experience, and gets points from Google (page speed score) then its definitely worth doing.

  3. Ken says:

    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.

  4. Ken says:

    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 says:

      @ 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!

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

  6. 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 says:

      @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.

  7. Eire32 says:

    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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

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



Looking for a registry cleaner to speed up your PC and show a full diagnostics?

Never miss an update from Papermashup

Get notified about the latest tutorials and downloads.

Subscribe by Email

Get alerts directly into your inbox after each post and stay updated.
Subscribe
OR

Subscribe by RSS

Add our RSS to your feedreader to get regular updates from us.
Subscribe

Get in contact

Please use the form below to get in touch.

About Me

I'm Ashley Ford, Co-founder and Technical Director at Harkable.com London, UK. Previously I worked at InMobi, Spotify and MySpace. My interests include photography and making short videos I'm also an avid F1 fan. I'm always working on side projects. Here are a few: Easy Poll, We Deliver.



What do you specialise in?

I spend a lot of time coding in PHP and MySQL, as well as front end XHTML and CSS. I also specialise in javascript and the jQuery framework as well as being an avid designer. You can find me on dribbble

Interested in advertising?

If you'd like to advertise on Papermashup.com you can find details here Or use the contact link below for further advertising opportunities.

How do I contact you

You can contact me here. and I'm available for consultation, freelance, programming book reviews.

Get on the mailing list

Join over 3000 people who have subscribed to the Papermashup inbox message, and be the first to find out about tutorial, competitions and giveaways.