Categories
General Site News

Joomla : Using a CDN/Setting Up Your Own

Joomla : Using a CDN/Setting Up Your Own

Like me you’ve probably read the hype about Content Delivery Networks that keeps doing the rounds. Want to energize/supercharge your blog?!…heh.

Still, being in the mood to improve the sites I host I decided to give it a go and see if the reality lived up to the hype. I suppose part of me missed the feature I never got to properly try on iPage – the Akamai CDN plugin. This would probably have been easier to setup with that!

Why?!

Why you ask? Well the science behind it is simple really. Most modern browsers support up to 6 concurrent connections per hostname (http://www.browserscope.org/?category=network&v=top), by using multiple hostnames you can download content in parallel, or put simply, using two hostnames would allow 12 concurrent connections for your site content, three would provide 18 etc. There are limits as to how effective this become, and most would suggest that you don’t go above four hostnames for your content. You’ve also got to have the bandwidth available to download using all of these concurrent connections so those poor users still on dial-up are unlikely to benefit much.

Who and Where?!

There are a lot of paid services from companies like Akamai, MaxCDN and Amazon, and there are a few free services from companies like CoralCDN, CloudFlare and Incapsula, you can also setup your own CDN (a very limited version of any of the previously mentioned companies) using a subdomain, I’ll also show you how to do this. Using a paid for service, like most things in life, will get you the most functionality, but that doesn’t mean that the others are worth a look.

For my requirements a paid for service wasn’t really necessary so I opted to try CloudFlare and also making my own subdomain and serving content from there. Again, as per my recent article on hosting companies, I’m not fussed which one you choose, or if you choose to use one at all in fact – I opted to use my own subdomain in the end. Why do I say limited? Simply because you’re still restricted to a single host really, and the same host if you follow my guide below. Using a provider like CoralCDN or CloudFlare you’re providing content closer to your users as these networks have servers around the globe as opposed to your single(?) server.

Many other options are out there, this article is designed to get you looking at what is available and testing a few of these options.

 

CloudFlare (or Incapsula)

Initially I setup a free account with Cloudflare and moved this website across. The setup is relatively simple, in a nutshell all you need to do is:

  1. Sign up for an account with Cloudflare or indeed Signup for an account with Incapsula
  2. Change the DNS server with your registrar (you probably shouldn’t be doing this if you don’t know how!)
  3. Wait 24 hours for statistics to show in your account

Some of the benefits of CloudFlare (or similar with Incapsula) I particularly liked, amongst others, are:

  1. Offload bandwidth requirements for static content
  2. Additional security including a challenge/response page from known troublesome IP’s (some may not like this)
  3. Add IPv6 connectivity at the touch of a button

The end result with CloudFlare was that I had visibility of a number of inbound threats to the site which I was unaware of. That said there was very limited feedback as to what exactly those threats were; more information available if I had the paid service – which to be honest I can’t argue with. That said, I’m not sure the site was any faster, GTMetrix showed improved grades but slightly increased page load times. The difference was only a couple of seconds, but that seemed to defeat the object.

I was also slightly uncomfortable with handing over control of my domain’s DNS to a service provider I’m not paying anything to… yes I’m probably a control freak, but I’m always suspicious when I’m getting something for nothing. I’m going to revisit the CloudFlare TOS when I have time, maybe I can convince myself this is not an issue!

At the end of the day, there is no bandwidth limit on using the free package, improved security and even caching of your site when your server is unavailable (for a limited period).

CoralCDN

Another freebie, with limited functionality but worth considering is CoralCDN. You’ll find you are able to browse your site using the url http://yourdomain.com.nyud.net – this is the CoralCDN. In order to take advantage of this CDN simply edit you .htaccess file using the following lines, changing yourdomain.com to match the site you wish to provide the CDN for:

  Header append X-Coral-Control “redirect-home”

  RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx

  RewriteCond %{QUERY_STRING} !(^|&)coral-no-serve$

  RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png)$ [NC]

  RewriteRule ^(.*)$ http://yourdomain.com.nyud.net/$1 [R,L]

There are some error detection features built into this code which is a modification of code that is available here.

Again, YMMV but I saw increased load times, despite my GTmetrix grades staying the same.. 3 seconds to 43 seconds does not warrant the same grade!!

The DIY Approach

So free is not cheap enough for you, or you simply want to keep control of what is yours. Note that this is a DIY specific to Bluehost and Hostmonster simply because this is what I have access to. Essentially, regardless of your hosting solution,  all you need to do is create a subdomain that shares the same document root as the website you’re setting the CDN up for in the first place. This is really important as it means you wont have to keep the content sync’d across multiple folders.

  1. From your cPanel select Subdomains
  2. Create a new subdomain, for example cdn.yourdomain.com – ensure the document root is the same as your website that you want to use the CDN for. 
  3. Finally modify your .htaccess file to include the following lines:

  RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]

  RewriteCond %{REQUEST_FILENAME} \.(css|js|txt|ico|pdf)$ [NC]

  RewriteRule ^(.*) http://cdn.yourdomain.com /$1 [R,L]

This will simply redirect all css, js, txt, ico and pdf files to your new subdomain. You can change what is redirected by modifying the REQUEST_FILENAME filter which is set to (css|js|txt|ico|pdf), to add zip files for example change this to (css|js|txt|ico|pdf|zip) .

Whilst the GTmetrix benchmark grades didn’t really shift that much I definitely noticed improved load times from doing this, but as always YMMV. Again, we’re not talking significant margins, at the end of the day there isn’t that much content on the site.

Good luck with whichever solution you decide works best for you, bear in mind that this is probably not necessary in the majority of situations – high traffic and high bandwidth sites will more than likely benefit from either solution, that said, if you’re like me and can’t leave these things alone, there is still some benifit to be had.

Leave a Reply

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