Creative and Technology • 8th Jul, 15
Site performance tools are plentiful and many options are available to the budding webmaster in order to increase site speed and overall performance. One such recommendation is using a Content Delivery Network or CDN. While many believe setting them up are difficult, expensive or only reserved for large companies; they are in fact relatively easy and simple to set up.
What are Content Delivery Networks?
CDN’s are a network of web servers that cache content from your website, providing all kinds of benefits to the site. Benefits include visitors to your site downloading content from the CDN instead of directly from your website which in turn reduces load on your site and frees up resources to handle remaining requests. In addition, CDN servers may even be located closer to your visitors geographically, resulting in a much shorter download time.
Setting up a CDN
There are a plethora of CDN services both free and paid, and even pay-as-you-go service plans. Examples of some services are CloudFlare, which is free, Amazon CloudFront which offers pay-as-you-go that charges by the gigabyte and MaxCDN which offers plans that start from just $9 per month. There are of course pro’s and con’s to whichever option you choose to utelise. The advantages of using a CDN doesn’t stop there as some sites like CloudFlare even going a step further to introduce protective measures for their clients to help ease the streamline between good users, bots and malicious users.
Once you’ve selected a suitable package, the easiest way to get going is to configure your CDN to pull content from your site. This is called “Origin Pull” or “Pull Zone”. The purpose of this is to tell the CDN where to get your content so that when a request comes in, the CDN will return the content it has cached, or if it doesn’t have a recent copy, it retrieves the content from the specified source.
The CDN provides you with a domain name you use to access the CDN content, this name may usually be configured to a domain name of your choosing. You might also have heard of a “Push” CDN which offers better performance, but are much more challenging to set up.
How do sites configure to use CDN’s
Once your account has been set up, how does one go about getting your site to use the CDN? That’s as simple as changing the URL’s that reference static site content to referencing the same path but on the CDN domain. For example, your site might be www.example.com and your resource, in this case a CSS document could be located at /style.css. Your link would then change from www.example.com/stlye.css to cdn.example/style.css. How this is done would of course depend on your site framework, but more often than not you may change either where the links are generated or as part of an output post-processing step.
For the assets to load from the CDN, you do need the full CDN domain in the resource URLs. Once completed, your site would then be loading content via the CDN, and in the event of the CDN not having a copy of the requested content, it automatically retrieves the content from your server and caches a copy throughout its network to use and help speed up your site.