Skip to content

What is a CDN?

A CDN (Content Delivery Network) is a network of servers spread around the world that keep copies of your site's files and serve them to visitors from the nearest location. Instead of one server in London handling guests from both Sydney and Manchester, your site is "delivered" by whichever server happens to be closest.

In short

  • A CDN is a network of servers that keep copies of a site's files close to its visitors.
  • The site loads faster, and your own server gets far fewer requests.
  • It also helps with sudden traffic spikes and DDoS attacks - but a small local site often does not need one.

Warehouses closer to the customer

Think of an online shop with a single warehouse in one city. A parcel to the next town arrives tomorrow; one to another continent takes a week. Big shops solve this by keeping their best-selling products in warehouses in many countries. You order, and the parcel leaves from a warehouse around the corner.

A CDN does the same with files. Your server is the head office, and the CDN's edge servers are the local warehouses. When someone in Japan opens your site, they get its images and scripts from a server in Tokyo, not from yours.

Why distance matters

Data travels across the Internet very fast, but not instantly. Every request is a round trip, and a page is made of dozens of files. Add a few tens of milliseconds to each one, and a site on the other side of the world loads noticeably slower than one next door.

A CDN shortens that trip. And because it keeps copies of your files (it is simply a cache spread around the world), your server answers only a fraction of the requests. That way even cheap hosting can handle a lot more.

What else a CDN gives you

  • Resilience to traffic spikes - your article made the front page of a big news site? The CDN takes the traffic, not your hosting.
  • Protection from attacks - in a DDoS attack, someone floods a site with millions of requests. Large CDNs have so much capacity that they can filter that traffic out before it reaches your server.
  • HTTPS and newer protocols - many CDNs include an SSL certificate and support faster versions of HTTP without you configuring anything on your server.
  • Image optimisation - some CDNs resize pictures for you and convert them to lighter formats such as WebP.

Well-known CDNs include Cloudflare, Akamai, Fastly, Amazon CloudFront and Bunny. Many have a free plan that is more than enough for a small site.

How you plug it in

Usually through DNS. You change your domain's settings so that traffic goes to the CDN first, and the CDN fetches whatever it is missing from your server. Visitors notice nothing - the site's address stays the same.

One thing to remember: after you change something on the site, the CDN may keep showing the old version for a while. Most of them have a "purge cache" button for exactly that.

CDNs for libraries and fonts

There is a second meaning too: public CDNs that host ready-made libraries (jsDelivr, cdnjs) and fonts. Instead of uploading the files to your server, you paste a link and you are done. Convenient - but remember that your visitor's browser then connects to someone else's server and hands over its IP address. In 2022 a German court ruled that loading Google Fonts from Google's servers without consent breached the GDPR. That is why more and more sites host their fonts and libraries themselves.

When it matters to you

  • Your visitors come from many countries - a CDN speeds the site up most for exactly them.
  • You serve lots of images or downloads - but compress them first, because the fastest file is a small one.
  • You expect a sudden rush - a campaign, a launch, a mention on TV.
  • You run a small local site on decent hosting - then a CDN is a nice extra rather than a must.

cache, DNS, server, cloud, DDoS.

Advertisement