What Is a CDN? And When To Use a CDN For Your Website
At the time of writing this post, this website isn’t connected to a Content Delivery Network (CDN) as of yet. Though I’m planning use one in the near future as my website starts to grow.
What is a CDN?
A Content Delivery Network (CDN) is a network of servers geographically distributed around the globe. Storing a website’s static content on these servers, minimizes delays for loading webpages. As the physical distance between a website’s visitor and the server is reduced.
The main benefit of using a CDN is increasing your website’s speed. Though this isn’t the only benefit of using a CDN, and there use cases where you don’t actually need one.
A CDN explained in layman terms
A website is nothing more than a bunch of files stored on a computer (server) which is connected to the internet. When someone visits your website, their browser will first try to locate the web server (computer) on which your website is hosted.
Once the connection is established, the visitor’s browser will download all the files needed to properly display the website. How many files and what kinds are required, depend on the content which needs to be displayed. Below you’ll find some example files types:
If you’re hosting a website without the use of a CDN, all these files will be downloaded from your web server. Though when you make use of a CDN, these files will be stored (cached) on a network of servers spread over many different locations around the world.
[Image world web server | world CMS servers]
Although the internet is lightning fast, the bits and bytes still need to travel the distance. I’ll show you what kind of impact this has, by sharing test results for this website. After we’ve analyzed these test results, I’ll share the benefits of using a CDN in more detail.
To make your life a bit easier I’ve added a table of contents below:
This website’s performance without using a CDN
This website is hosted on a server which is part of a data center located in New Jersey (NY). A data center is a specialized warehouse in which you can find hundreds if not thousands of operational servers. Most data centers have a direct connection with the internet backbone.
I could have picked a data center located in the Netherlands (my home county). As my web hosting provider also offers servers which are located in Amsterdam. Though I’ve chosen to host my website in New Jersey, as my target market is actually located in the United States.
And I’ve done so for good reason, as you’ll find out from the test results in the table below.
To generate these results, I’ve used two online tools. The 2nd and 3rd columns represent the results I got from Dotcom-Tools. The results in the 4th column are courtesy of Pingdom. I’ve run several tests and averaged out these numbers, as there are always some fluctuations.
|Location||DCT 1st||DCT 2nd||Pingdom|
|North America (EC)||0.6||0.6||0.2|
|North America (WC)||1.3||0.8||0.6|
Based on these results, I concluded this website is lightning fast in North America. Which is what I expected, as my website in hosted in the state of New York. Though at the other side of the globe it takes at least 2 to 6 times longer to load this website.
You might be wondering why I’ve added the “DCT 2nd” column to this table. Well, Dotcom-Tools actually measures your website’s speed twice. Once for the initial visit to a web page, and another measurement for a second visit to the same page.
The time it takes to load a webpage for the second time is much shorter. This is because the files which have been downloaded, are stored on your computer’s hard drive (Browser Cache).
When you visit a web page for the second time, your browser will use its cache. Though it only does so for specific elements of the website, like the logo for instance. This actually saves a lot of loading time, as your browser won’t have to download the same files again.
As mentioned before, my target market lives in the USA. As this is where the majority of the English speaking people in the world live. Though I’m actually doing a disservice to my readers who live at the other side of the globe. And this why using a CDN can be beneficial.
A CDN’s main purpose can be derived from its name. It’s a network of servers dedicated to deliver content. The servers in this network are strategically positioned on many geographical locations around the globe.
This shortens the physical distance between a browser and a website’s server. And because of this, a website’s loading time will be shorter as well. Though this isn’t the only benefit of using a CDN, as you’ll learn in the upcoming subsections.
Next up: Website performance factors which can be improved by using a CDN. Though I’d like to finish off this subsection with some revealing information.
Full Transparency: I haven’t added any (featured) images to my blog posts as of yet. And this is why the results in this table are still somewhat acceptable. Though because it’s the holiday season right now, I’ll be having some time on my hands to add some of these images.
My guess is this will have a major impact on my website’s loading times, especially at the other end of the globe. Image files are much larger than any of the other files which make up my website. If you’re interested in the actual effects, have a look at this post:
The Effects Of Adding Images To This Website
Website performance factors (influenced by a CDN)
There are many factors which can influence a website’s speed. Though, I’ll be focussing on the main ones which can be improved by using a CDN. If you’re already familiar in the world of websites, just bear with me. I’ll be sharing when it makes sense to use a CDN, in the next section.
Time To First Byte
The first factor is “Time To First Byte” (TTFB). Which in layman terms means, the time it takes to setup the connection between your browser and the web server. Before the connection can be established, your browser will need to know where the website is hosted.
It uses the Domain Name System (DNS) to lookup the web server’s IP address. Once the address is fetched, your browser will start setting up the connection. When this connection is established, your browser will start downloading the website’s files.
At this exact moment the timer for measuring the TTFB is stopped. Hence the name Time to First Byte. As it’s actually the time needed before your browser starts to download the very first byte.
Your browser will download the website’s HTML file first, as this is actually the blueprint of the website. This file need to be fully downloaded before your browser starts downloading all the other files.
Side Note: TTFB is not to be confused with a server’s response time. Server response time is measured by pinging the server’s IP address directly. The DNS lookup has already been done and is not included in this measurement.
* Bitcatcha is the perfect measurement tool for determining your server’s response time.
The second one is the combined size of all the files which need to be downloaded in order to display a webpage. The page size will either be measured in kilobytes (KB) or megabytes (MB). A 237 KB webpage takes less time to (down)load than one that’s 4.2 MB (or 4200 KB).
As I mentioned earlier on, I haven’t come around to adding any featured images to my blog posts. And I’ve set my homepage to display the blog posts I’ve written so far. This is why the actual page size is still very small, a mere 237.7 KB.
For most websites, images will account for big chunk of the total page size. This is why it’s always good practice to optimize images before you upload them to your website. Also use the JPG file format for most of your images, only use PNG for the transparent ones.
[Image of blog posts]
The third factor is the number of separate files which need to be downloaded (# of requests). Lucky for us, some of these files can be downloaded simultaneously. Which in turn lowers the total amount of time, before a web page is fully displayed on our screen.
Though the number of simultaneous downloads is actually limited, as there are limits to:
- The number of simultaneous downloads per domain
- The maximum total of simultaneous downloads
These limitations depend on the type of browser you’re using. And the number of domains on which these files are located. Chrome allows 6 connections per domain, with a maximum of 256. Internet explorer allows 12 simultaneous connections and 1000 as the upper limit.
These limitations can have an impact on a website’s loading time. As some of the files might be waiting on others to be downloaded. Though from what I’ve been able to test, the actual performance doesn’t really suffer.
I’ve already explained this fourth factor, as this is actually the most important one. The physical distance between a browser and server impacts all of the previously mentioned factors. As I’ll explain in more detail in the next section.
When to use a CDN for your website (Pros & Cons)
Although a CDN will have a positive impact for most websites, you might not need one. For instance, when you’re only serving a local market, and you’ve created a website using a local hosting service. There won’t be any benefit of using a CDN in this case.
Another thing to look into, is where the CDN’s servers are located. If there aren’t any servers located nearby your target market, it doesn’t make sense to use that vendor. So be sure to do your research before you actually connect your website.
In some cases it makes sense to wait a while, before making this decision. For instance, when you’re using already using a premium web hosting service, like I am. Or if you’re just getting started on creating your own website, and don’t have a lot of traffic yet.
It makes sense to wait until your website starts to get some traction. This is actually the main reason why I haven’t connected my website to a CDN, as of yet. Based on the results I showed you earlier on, I’m able to cover North America and Europe without any issues.
You might be at a crossroads right now. So here are a few guidelines to determine if it makes sense to use a CDN:
- Your website is growing exponentially and worry about traffic spikes
- Most pages on your website have a page size of more than 1 Megabyte
- Foreign traffic is starting to increase
Always keep in mind, you’ll have to run some tests before and after implementing a CDN. As you’ll want to understand the impact your CDN is having. It just doesn’t make sense to pay for something which doesn’t improve your website’s performance.
Speaking of performance, let’s dive into the benefits of using a CDN.
A website’s content can be cached by CDN servers. Which means these files will also be available on servers closer to a website’s visitor. As a result of this, the bits and bytes can travel a shorter distance, resulting in a faster website.
As mentioned before this actually impacts all stages of loading a website. I’ve done a more comprehensive test on this website, where I’ve included the use of some images. I singled out the loading times for just the images and displayed them in the small table below.
As expected the loading time increased dramatically. It took just 0.05 to download 1.9 MB of images from Washington DC. Though in Frankfurt this already took 10 times as long. And loading this web page from Sydney even took 25 times longer.
So I think it’s safe to say a CDN will benefit this website. As it will reduce the loading times for my australian friends.
Though this isn’t the only performance benefit of using a CDN. As you might recall from the previous subsection, there’s something called “# of requests”. This is the total number of files which need to be downloaded in order to properly display a website.
You’re able to choose which type of files you’ll be offloading to the CDN’s servers. These servers actually have a different domain, allowing you to double the number of sequential downloads. Although this won’t make a major impact, it’s still a benefit.
Another benefit of using a CDN is your website will be available from multiple servers. So if you ever experience a traffic surge, your CDN will act as a shield in front of your website. As the CDN will handle the load, hence your website will stay quick and available.
This is actually the perfect segway to next type of benefit.
As I’ve just mentioned using a CDN means you’re website will be shielded. Not only for traffic spikes due to a successful marketing campaign. But also against more malicious threats like DDOS attacks. DDOS stands for Distributed Denial Of Service.
The goal of a DDOS attack is to make your website unavailable. This type of attack is used by hackers, who’ve taken control of a network of computers (Botnet). By flooding your website with requests from their botnet, they’re hoping to take your website down.
Luckily most CDNs offer an additional layer of protection and more. Like load balancing, hotlinking protection, token authentication, and so on. As every CDN offers different kinds of protection, this is out of the scope for this blog post.
Some countries are trying to prevent their citizens from accessing certain websites. In some cases you’ll be able to bypass these kinds of restrictions by using a CDN. As the server on which your website’s files are stored is located in that country.
You could connect your website to a free CDN like Cloudflare. Though from what I’ve heard the performance boost is negligible. In all fairness this is word of mouth information, I still need to test all this myself. Though based on past experiences: “You always get what, you pay for”.
And this is actually a drawback, as a CDN can add to your website expecess. And this on top of the monthly or annual bill you get from your web hosting service provider. I’ll be testing out at least 2 CDNs for this website: BunnyCDN and Cloudflare, so stay tuned.
Another potential drawback depends on the type of information you store on your website. A CDN will copy your website, including all sensitive information, to many different servers. So it’s best to keep sensitive information separate from your main website.
However unlikely, there’s still a chance a CDN can go down. If this ever happens, your website won’t be accessible anymore. This is why it’s a good idea to keep your web hosting, domain (DNS records) and CDN separate.
When something happens to your CDN, you still have the ability to change the DNS settings and point your domain directly to your web server. If you’re running a large website, it’s also a good idea to set up some kind of uptime monitoring.
The final drawback depends on if you’re using a Content Management System (CMS) or not. If you chosen to develop your website using code. You may end up having to change many lines of code in order to connect a CDN.
It’s easy to spend days or even months researching this topic. Though in the end it all comes down to common sense. If you’re growing your website and page speeds are okish, you don’t need a CDN right now. There’s nothing wrong with education yourself, just don’t overdo it.
At this point in time I can’t actually recommend any CDN providers, as I haven’t tested any of them myself. Though if you’re willing to take the time and do some tests yourself, here’s a short list of CDN’s I’ve heard good things about:
- BunnyCDN (14-Day Trail)
- Cloudflare (Freemium)
- ArvanCloud (Freemium)
- StackPath (Demo)
- Fastly (Freemium)
Though always make sure you run an extensive test on your website first. Once you’ve got this data, connect the CDN of choice and wait for the DNS servers to propagate. It can take up to 48 hours before the CDN can do its job properly.
Once you’re ready, make sure to run several tests instead of just singe pass. As your content still needs to be dispersed across the globe. And don’t forget the compare this data to the initial test, as this comparison will show you the actual result of using a CDN.
Oh, and on more thing. Do not change up the content on any of the pages you’re testing, as this will skew the results you get. Setup a proper test page which also contains several large images. To test your website’s loading times, these are the tools I recommend using: