Papermashup

Subscribe


Tweets


"RT @bethgordon: .@Tesco Please rethink archaic 'Approved by Mums'. Pretty sure it's not just mothers who make childcare decisions. https://…"

@ashleyford 2 days ago

"Is there ever a time that @DFS doesn't have a sale on?"

@ashleyford 6 days ago

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Using subdomains to speed up your site

AshleyAshley

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:

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.

Designer and web developer, Co-founder and Technical Director at Harkable.com. Previously I worked at Spotify, MySpace and InMobi. Contact me - ashley[at]papermashup.com

Comments 9
  • Stephan Pieri
    Posted on

    Stephan Pieri Stephan Pieri

    Reply Author

    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?


  • Jobst
    Posted on

    Jobst Jobst

    Reply Author

    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.


  • Ken
    Posted on

    Ken Ken

    Reply Author

    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.


  • Ken
    Posted on

    Ken Ken

    Reply Author

    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
      Posted on

      Ashley Ashley

      Reply Author

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


  • Maicon Sobczak
    Posted on

    Maicon Sobczak Maicon Sobczak

    Reply Author

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


  • Brian Johnson
    Posted on

    Brian Johnson Brian Johnson

    Reply Author

    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
      Posted on

      Ashley Ashley

      Reply Author

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


  • Eire32
    Posted on

    Eire32 Eire32

    Reply Author

    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