How to Setup your own CDN in 30 minutes

Your website’s performance or speed is one of the factors that decides your ranking in search engines. Website that loads quickly also improves user experience and helps build loyal readership.

Improved site speed is also a good SEO practice. Google as well as Yahoo! suggest in their Performance Best Practices that serving static content from a cookieless domain or using a Content Delivery Network (CDN) helps. This reduces total size of the requests made for a page. In this article, I will explain you how to you implement this in 30 minutes flat.

Using a  CDN for a small website or blog would be expensive. So is there a way we can set up our own CDN or a cookieless domain from which we can serve the static content? The answer is Yes! And I will describe the steps to achieve this.

What is Static Content?

Static content is the content such as images, Javascript and CSS files that are served along with your webpage. Server sets cookies for all the HTTP requests. So small cookies get attached to these static content as well. However, since there is no direct user interaction with these resource, they need not have cookies attached. We can reduce the request size by serving these resources from a CDN or a cookieless domain.

What is a CDN?

A content delivery network (CDN) is a collection of web servers geographically distributed across the globe. The server with the fewest network hops or the server with the quickest response time is chosen to deliver the content, thus improving response time. CDN is generally used to serve static content and does not set any cookies. Thus the request size is also reduced.

How to setup our own CDN or a Cookieless Domain?

Easiest way is to setup a CNAME record aliasing your static domain to your main domain. You will need register a separate domain name to do this or you can use a subdomain of your domain.

If you do not have a separate domain, create a subdomain using your site’s control panel. Make sure that the subdomain points to your main domain’s root folder.

cdn-sub-domain

Now that you have a domain or subdomain to serve static content, go to the DNS Zone Editor of your website’s control panel and create a CNAME record as shown.

cdn-cname

Add the domain/subdomain you created earlier to the Name/Label/Alias of CNAME record. It should point to your main domain i.e. www.riyaz.net in this case.

If you are using a subdomain, you need to do one more step to make sure that no cookies get set on this subdomain. Two common cookie setters are WordPress and Google Analytics. Rob Flaherty has explained in easy steps how to prevent these sites from setting cookies on your static subdomain. The section ‘Separate domain or subdomain?’ explains how to get read of the cookies.

Now that you have setup a CDN or cookieless domain/subdomain, how do you actually serve your static content from this new location? Do you have to move the static files to this location? Not at all. You only need to modify the references to your static files (images/media/Javascript/CSS/text files etc.) to point to the new location.

e.g. http://www.riyaz.net/images/myimage.jpg will now become http://cdn.riyaz.net/images/myimage.jpg or http://www.mycdn.com/images/myimage.jpg

But this could be a cumbersome task. How do I do this quickly? Simply use the W3 Total Cache plugin from W3-EDGE and enable CDN. Use Mirror as CDN Type.

cdn-w3-total-cache

Now go to CDN Settings of the plugin and set the Configuration parameters as shown below:

cdn-configuration-w3-total-cache

You may leave the other parameters to their defaults.

Thus you have setup your cookieless static content provider.

More reading:

This entry was posted in Blogging, Internet, Technology, WordPress and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
Around the Web »»

15 Comments

  1. Posted June 20, 2010 at 4:24 pm | Permalink

    Still confusing, how to make sure there is no cookies in my subdomain?
    arithok recently posted..WordPress 3.0 DirilisMy ComLuv Profile

  2. Posted June 20, 2010 at 10:02 pm | Permalink

    Google Analytics and WordPress are most common cookie setters. Rob has explained in detail how to get read of these cookies in his article – http://www.ravelrumba.com/blog/static-cookieless-domain/. See the section on Separate domain or subdomain?.

  3. Posted July 24, 2010 at 3:05 pm | Permalink

    Just what I’ve been looking for – an easy to understand tutorial for cookiless domains.

    I’m not sure if it’s worked for my site though as I ‘think’ my new subdomain is still serving the cookies. Followed the extra part you advised on Rob Flaherty’s site regarding wordpress & google cookies.

    Help a newbie – how can I be sure the subdomain doesn’t serve cookies?

    • Posted July 24, 2010 at 6:28 pm | Permalink

      Try installing Firebug and Pagespeed addons on your Firefox browser and check what cookies are being set. If those are from WordPress or Google Analytics, then Rob’s method should help.
      Riyaz recently posted..Three Ways to Improve Your Blog WritingMy ComLuv Profile

      • Posted July 25, 2010 at 8:18 pm | Permalink

        Thanks Riyaz,
        According to Firebug it’s one of my images so I’ve got the feeling I must have done something wrong when going through your tutorial, but what that might be I simply don’t know?

        The only part I got slightly confused over was setting up the subdomain/CNAME as my host has different names for boxes that are shown in your example. Saying that, I think I managed to set them up successfully.
        Niko recently posted..Homemade Healthy Dog BiscuitsMy ComLuv Profile

        • Posted July 25, 2010 at 10:15 pm | Permalink

          Are you able to access the images using the new subdomain url? If you are able to do so, then you have set up the subdomain correctly. Then you can use W3 Total cache to easily replace the old urls with new ones.

          Then you can proceed to get rid of the cookies as Rob explained.

  4. Posted July 27, 2010 at 1:58 am | Permalink

    I can now but not initially after finishing the tutorial. At first I was getting white boxes where all my pictures should be so I physically copied all my images to the new subdomain.

    Is that something I did wrong?

    • Posted July 27, 2010 at 9:33 am | Permalink

      You dont need to physically copy the files anywhere. Actually when you set up your subdomain, you create only a CNAME and not the A record. Check if any A record is created. If so, change it to a CNAME entry.

      The new subdomain should point to the original domain’s root folder. Now the images or any objects should be accessible via the new URL.

      Then simply put the subdomain name in W3 Total Cache CDN settings and it should work.

      • Posted July 27, 2010 at 12:50 pm | Permalink

        Ahhh….
        So I did it wrong then, that’s why it hasn’t worked the way you’ve suggested.

        Thanks so much for your points, I’m going to go back and try again. Will update again here when finished in case anyone else gets the same issues I had!

  5. Posted July 27, 2010 at 8:32 pm | Permalink

    Hmm
    I made some progress :-)
    But still not right :-(

    Made a totally new subdomain, and updated W3TC with it and it worked first time in that I didn’t need to physically transfer any files across, so progress yeah!

    But still firebug reports cookies being set on this new domain. Nearly there – but not quite!
    Cookie is listed as
    utma=87976967.1178402482.1279961553.1280232849.1280234375.8; __utmz=87976967.1279961553.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)

    Does that look like a cookie should look like? Certainly welcome any suggestions – you’ve been great so far!
    Niko recently posted..Homemade Healthy Dog BiscuitsMy ComLuv Profile

    • Posted July 27, 2010 at 9:03 pm | Permalink

      Great!
      This looks like Google Analytics cookies. Check Rob’s article on how to tweak Google Analytics code to not set cookies on the entire domain.

      • Posted July 28, 2010 at 8:54 pm | Permalink

        Well I think I need to give up on this one, taking too many of my hours up lol.

        Can’t get it to work but I think it’s W3TC and it’s configuration rather than the tutorial that’s causing it.
        Thanks for all your input though :)

        • Posted July 28, 2010 at 8:59 pm | Permalink

          In W3TC, on the General Settings page: just select the check box to enable CDN and choose Mirror as CDN Type and save changes. Then on the CDN Settings page under ‘Replace site’s hostname with’ specify your subdomain url. Save changes and you are done.

          • Posted July 29, 2010 at 12:18 am | Permalink

            Yeah I did all that but back to square one again, just getting white boxes where my images should be.
            Error log says something about too many redirects, maximise the number of redirects allowed but I couldn’t find anything on google about it.

            I’ve already taken up so much of this thread – and it’s only a comments page!
            Niko recently posted..Homemade Healthy Dog BiscuitsMy ComLuv Profile

  6. Posted August 17, 2010 at 11:35 pm | Permalink

    Very interesting..
    nice tips.. i’m still looking any tips to make my blog fast loading..
    maybe i should try this tips..
    Azuan recently posted..Contest Hidup Seorang Blogger Anjuran Hidup Untuk MemberiMy ComLuv Profile

One Trackback

  1. [...] H&#959w t&#959 Setup &#1091&#959&#965r &#959w&#1495 CDN &#1110&#1495 30 minutes | riyaz.net [...]

Post a Comment

Login with your Facebook or Twitter Account to comment. Alternatively, please fill in the fields marked *.

.

Connect with Facebook

*
*

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>

CommentLuv Enabled

Subscribe without commenting

GetSocial