To further optimize the performance of your site, you can and should use a Content Delivery Network.
What is a CDN?
Content Delivery Networks or CDN’s cache the static assets on your site and distribute them across servers that are placed all over the world. Then, when someone visits your sites, they’re visiting the servers from the CDN, not your server, and pulling content from the CDN servers into their computer. This dramatically improves performance because the CDN servers are likely to be closer to the user, are likely to be more powerful, and are likely to have much bigger bandwidth than what you have on your server.
Why use a CDN?
There are many reasons to use CDN but the most common reasons are as follows:
Without a CDN, when a visitor goes through your site they’re requesting data directly from your server and your server will send that data up through whatever connection it has to the visitor. There are some obvious issues with this. First of all, the distance between the server and the visitor has a huge role to play in performance. If the visitor is in Eastern Europe and your server is in the United States, then every piece of data has to travel across the Atlantic to get to the visitor, and that will just take a lot of time. Secondly, if there are a lot of visitors to your server, your server will have a hard time providing the files because it needs to use a lot of resources.
It will also have a bandwidth limit, how much data can push through the network at once and the more visitors you get, the more likely it is for your site to either slow down or break down completely. If you’re using a shared host, you also have to consider the other traffic on the network. You would typically be in a server with many other sites and if one of the other sites is very popular then your site will slow down. And finally, you have your server performance. If you are using a cheap service provider, then your server will probably be cheap and it won’t perform very well, especially under a lot of loads.
When we use a CDN all of this changes completely. Your server is only there to serve content to the CDN and the visitor gets their content directly from the CDN. That means the load on your server dramatically decreases and the CDN takes over the heavy lifting of feeding all the static content to the visitor.
In addition, there’s also the issue of malicious attacks. If you set up a server on the web, there’s a good likelihood at some point, someone will try to find out if your server is vulnerable and they’ll try to send out the spam to it or hack into it or attack with it with what’s known as a denial of service attack, where they just get a ton of computers to ping your server all at once to take it off the internet. With a single server, this is hard to protect against and the typical result of one of these attacks is your service provider will discontinue your service and take your site off the internet.
CDN’s typically have solid security features in place, so if someone tries to maliciously attack your site, they’re not getting to your server, they’re trying to attack the CDN itself and the CDN will have a firewall and other measures in place to prevent those attacks from actually hitting the files themselves.
This will protect both your server, your data, and the visitors that are coming to your site. So, in effect, using a CDN, you’re offloading the responsibility of your data to a much larger network of computers that’s far more suited to serve that data to the visitors. And of course, there is the global reach factor. If you have a server anywhere, there is a chance that you have visitors from somewhere else on the globe. CDN’s were created to serve up data from large providers like t.v. networks or very, very popular sites, and they were created because these sites were having trouble serving all this data across the entire planet.
Now, everyone can take advantage of this same technology and it’s not very expensive and the result is, your site doesn’t just live on the origin server, it lives everywhere in the world and any update on your origin servers get pushed out to all the servers across the world.
How to Pick the Right CDN?
Now that I got you interested in using a CDN, I, unfortunately, can’t tell you which one to use. That’s because there are so many different options and they all provide slightly different features. Instead, I’ll tell you how to pick the right one. If you want a solid CDN, here’s a good checklist to follow:
First of all, it must support HTTPS and HTTP/2 with all the features, including server push.
Not every CDN supports HTTPS and not every CDN that supports HTTP/2 also supports server push. So make sure this is a CDN that provides all the latest features, otherwise, you won’t get the benefit of all the stuff we’ve been talking about so far in the course.
Second, ask the CDN about their global reach and find out where their servers are. Some CDN’s only have servers in the United States or North America, while others have servers all over the world. And it’s important to match your CDN choice with the audience you have.
If your audience is primarily in North America, then you can go with a CDN with servers only here. If your audience is worldwide, then you have to make sure you have proper coverage. Also, ask about security features. Most CDN’s will provide a firewall and some DDoS protection, but it’s a good idea to check what you are getting before you buy it because the better protection you can get, the better your site is protected and the better your visitors are protected. Of course, the cost is a factor. The good news is, most CDN’s provide fairly cheap solutions now, you can get it from down to 10 to 20 dollars a month, but this all depends on the type of traffic you have, the type of security features you need, and how big your site is.
So, check the cost of a few different options and find one that fits within your budget. Finally, take the CDN for a spin to see how easy it is to use. Different CDN’s target different markets, so some are more enterprise-focused and quite complex, but give you a lot of detail control, while others are more consumer-focused and very simple, but give you very little control. So, here it’s important to pick a CDN that fits with your specific usage scenario for each site you’re working with. Now, here’s a caveat. Most hosting companies will claim to have CDN’s, but they’re just a bunch of large servers that they’re distributing your content over.
To get the full benefit out of CDN, you need to use a third-party CDN that only provides CDN services and nothing else. It will greatly impact your performance and it will probably also save you a lot of money in hosting costs. To that end, most hosting companies have CDN providers they collaborate with for one-click installs or few-click installs. If this is an option, check out how much money you’ll save by using that bundled option because usually, they come with a deal, and also check out if any limitations or any weird funkiness are going on in the setup to make sure you’re getting the service you want and need.
Finally, and this is important, use a for-pay provider. There are free options for CDN’s out there, but they are all suboptimal. In particular, most free options do not give you HTTPS support, which means you won’t have HTTP/2. To get the full benefit out of a CDN, you need to pay for it and you should pay for it, so make sure CDN’s are part of your overall budget for the site.