What’s a content delivery network and why do you need (or don’t need) it?
I’ll cover the basics of what it is, how it’s used, and how it may benefit or impede your website. I also explain the difference of traditional CDN’s which were made for speed and the confusing Cloudflare service which is a DNS-caching service that does similar things as traditional CDN but also provides extra security and DNS management.
What’s a CDN?
Content delivery networks are service providers that clone your server files to their servers, in order to serve them faster to visitors all over the world. This is extremely helpful for speeding up download times for images, CSS, JS, fonts, and other media used to load your website. The end result is your will provide a much better experience for users all over the world instead of only the users closest to your web-server.
Without a CDN:
- You have one web-server, let’s say in USA.
- All website visitors connect to your USA server.
- USA-visitors experience fast pageload times. Faraway visitors (like in Europe or Asia) experience slow pageload times.
- In case you’re wondering, the difference in loading files from nearby vs faraway server can be like 1-3 seconds!
With a CDN:
- You have one web-server, let’s say in USA.
- You configure your website to copy all static assets (images, CSS, JS, fonts, etc) to your CDN provider. Usually done through a simple plugin or your cache plugin.
- The CDN provider copies your files to all their servers, using a different hostname to call those files (cdn.yourdomain.com or yourdomain.theirdomain.com).
- As users visit your site, all your pages load from same domain URL but your assets will load from the chosen CDN hostname. (https://cdn.yoursite.com/image.jpg instead of the usual https://yoursite.com/image.jpg)
- Depending on where the user connects from, the CDN will intelligently route them to the nearest mirror server.
- All visitors now experience fast pageload times since they’re all connecting to a nearby server instead of all the way to your origin server.
What’s Cloudflare? (Is Cloudflare a CDN?)
This is a geek debate topic. In the traditional sense, some say Cloudflare is NOT a CDN because they’re not copying your files to a separate hostname and behaving like other traditional CDNs. But then again, Cloudflare is a CDN in that it does copy your files to their servers and serves them to users from the nearest server.
The main difference is that Cloudflare operates at the DNS level and is therefore taking more control of your website load process and can even offer other benefits. Some say this difference makes Cloudflare betters since it can give more features. Others say this makes Cloudflare inferior as a CDN since it doesn’t focus on just delivering content.
With traditional CDN:
- Your site copies files to CDN servers.
- Files are loaded from chosen CDN hostname (usually “cdn.yourdomain.com” or “yourdomain.cdndomain.com”).
- You change your nameservers settings from you registrar to point to Cloudflare (instead of your webhost).
- Cloudflare then copies all your DNS records (from your webhost) so everything works seemlessly.
- Cloudflare then silently loads your static assets (images, JS, CSS, fonts, etc) from nearby servers.
- All your asset URLs stay the same instead of changing to CDN hostname. (For example: if your images were loading from “https://yoursite.com/image.jpg” before, they will still load from the same URL.
- Some extra bonuses, since Cloudflare operates at the DNS level, they can protect your site from DDOS attacks. And also apply other performance and security rules.
- Cloudflare also has a free-service tier whereas all other CDNs do not.
So do you need CDN?
And now for the million-dollar question! Do you need a CDN?
- You only need it if you have far away traffic. And by “far”, I mean traffic that is faraway from your webserver. (How far is too far? I say if you have more than a few thousand visits/month coming from over 300ms away, you need it. Check ping times at WonderNetwork.)
- If your traffic is mostly local, you don’t need CDN.
- Web-server speed – this is another variable. If your webserver is really weak or can’t handle the load, adding CDN can definitely help take the load off your webserver. Most likely, paying for CDN is cheaper/better-performance than paying for a bigger server.
- If you have a busy site, ecommerce site, or a controversial site that baits hackers…get Cloudflare. Yes, even free Cloudflare can help a lot.
- Other security options (for VPS owners), get a DDOS-filtered IP from your VPS provider. Can also get Sucuri or another security provider where you pass your IP through their nameservers.
- Other security options (for shared-hosting), don’t worry too much. Haha, their shared server is probably configured to handle DDOS attacks. In case they’re not, it’s probably time you upgrade!
When (or why) NOT to get a CDN?
- Don’t get it if the CDN server is farther away from your visitors than your origin server. This can often be the case with smaller/free-tier CDNs. They might not have a nearby server or maybe they route you through cheaper/slower datacenter or network.
- You don’t have many files, or big files. Or files already browser-cached with long expiry times.
- You don’t have that many visitors.
- You want to save money. Then again, Cloudflare is free but not always good performance for all areas. (Cloudflare may even be slower than your origin server in some areas.)
- You have a simple site, and don’t need any more complexity in your setup.
Should you get Cloudflare or traditional CDN?
- That’s a whole other can of worms. I’ll cover that in another guide.