Skip to content
Grocito
← All posts

CDN Explained: How Content Delivery Networks Speed Up Sites

By Grocito

CDN Explained: How Content Delivery Networks Speed Up Sites

A CDN, or content delivery network, is a worldwide network of servers that keeps copies of your website's files close to your visitors. Instead of every request travelling to your main server, many are answered from a nearby edge server, which makes pages load faster and takes pressure off your hosting. Most CDNs also add security features such as DDoS protection.

Key takeaways

  • A CDN stores cached copies of your content on edge servers around the world and serves visitors from the closest one.
  • It helps most with static files and images, and can also speed up some HTML and API responses when configured carefully.
  • Caching is controlled by rules: how long content is kept (TTL), what makes two requests different (the cache key) and how you clear old copies (purging).
  • A CDN is not a replacement for hosting. Your origin server still holds the real site.
  • Common problems are stale content, personalised pages cached by mistake and cookies or query strings that prevent caching.
  • Test it, set sensible cache rules and keep an eye on usage rather than assuming it works.

What is a CDN in plain English?

Imagine your website's server is a single warehouse in one city, and distance adds delay for far-away customers. A CDN is like opening small depots around the world that stock your most requested items. A visitor collects from the depot nearby, and the warehouse only deals with items the depots do not yet have.

Technically, the CDN sits between visitors and your origin server. When someone requests a file, the nearest edge server checks whether it has a fresh copy. If so, that is a cache hit and it responds immediately. If not, that is a cache miss: it fetches the file from your origin, serves it and stores it for the next visitor.

What does a CDN speed up?

  • Static files: images, stylesheets, scripts, fonts and downloads. These rarely change, so they cache well. This is where most of the benefit lies.
  • Images: many CDNs can resize or convert images on demand. Combine this with good habits from our guide to image optimisation for faster websites.
  • HTML pages: pages that are the same for everyone, such as marketing pages and articles, can be cached at the edge. Pages that differ per visitor need care.
  • API responses: public, rarely changing data can be cached briefly, which reduces load on your servers.

A CDN also reduces the work your origin does, which helps in traffic spikes. It can improve Core Web Vitals, though it cannot fix heavy scripts.

How does CDN caching work?

TTL: how long content stays

The time to live (TTL) is how long an edge server may reuse a stored copy before checking with your origin again. A long TTL means faster delivery and less load, but changes take longer to appear. A short TTL means fresher content but more trips to your origin.

Cache keys: what counts as the same request

A cache key is the combination of details the CDN uses to decide whether two requests are the same, normally the address plus certain headers or query strings. If the key includes something that varies unnecessarily, such as a tracking parameter, the CDN stores many copies of the same file and rarely gets a hit.

Cache-control headers

Your server tells the CDN and browsers how to cache using response headers. In words: one header says whether a response may be stored publicly, how many seconds it stays fresh and whether it must be checked again. Another lets the CDN ask the origin whether a file has changed instead of downloading it again. Your developer should set these deliberately for each kind of content.

Invalidation and purging

Purging removes content from the cache so that the next request fetches a fresh copy. You can purge one file, a group of files or everything. A common technique for static assets is to put a version or content fingerprint in the filename, so a new file is a new address and old caches simply stop being used.

What security features do CDNs offer?

At a plain level, many CDNs add:

  • DDoS mitigation: absorbing floods of junk traffic across the network so your origin is not overwhelmed.
  • Web application firewall (WAF): rules that block common attacks such as malicious form input.
  • Bot management: distinguishing helpful crawlers from scrapers and abusive bots.
  • TLS and HTTPS: managing certificates and encryption between visitors and the edge.

These are layers, not a complete security plan. See our website security checklist for the rest.

What is the difference between a CDN and web hosting?

Hosting runs your application and stores your real data. A CDN delivers copies of your content from the edge. You need hosting; a CDN is an optional layer in front. If you are choosing between hosting types, read web hosting explained: shared, VPS, cloud and managed. Some hosting platforms include a CDN, which is convenient but worth checking.

When does a small site benefit from a CDN?

A CDN is most helpful when:

  • Your visitors are spread across regions, far from your server.
  • Your pages have many images or large files.
  • You have traffic spikes from campaigns or seasonal sales.
  • Your origin server is modest and needs shielding from repeated requests.

It adds little when:

  • Almost all your visitors are near your server and the site is light.
  • Most pages are personalised or behind a login.
  • The slowness comes from heavy code or a slow database.

What problems does a CDN cause?

  1. Stale content after updates. Visitors still see the old version. Fix with purging, shorter TTLs for frequently edited pages or fingerprinted filenames.
  2. Personalised pages cached by mistake. If a page showing one customer's basket or account is cached and served to another, that is a privacy incident. Never cache pages that depend on a login unless you are certain of the rules, and test with separate accounts.
  3. Cookies breaking caching. Responses that set cookies are often not cached. Remove unnecessary cookies from static assets and public pages.
  4. Query strings creating many copies. Tracking parameters multiply cache entries. Make the cache key ignore parameters that do not change the content.
  5. Conflicting headers. Contradictory caching headers lead to unpredictable results, and it is hard to tell whether the browser, the edge or the origin is responsible. Check headers that report cache status.

How do you test whether a CDN is working?

  • Request a static file twice and check the response headers for a cache status indicating a hit on the second request.
  • Compare load times from different locations before and after.
  • Make an edit, purge, and confirm the new version appears.
  • Test logged-in and logged-out views, and two accounts, to confirm personal pages are not shared.

How do you control CDN cost?

You can keep usage predictable without knowing any prices:

  • Cache what can safely be cached, and compress images and files before delivery.
  • Set up alerts on traffic and data use.
  • Understand how your provider measures usage, such as data transferred or requests, and what happens during an attack or a traffic spike.

Our guide to cloud cost optimisation covers the same discipline more broadly.

Setup checklist

  1. List which content is static, which is public HTML and which is personalised.
  2. Choose a CDN and confirm it supports certificates for your domain.
  3. Point your domain through the CDN, following the provider's documentation.
  4. Set cache rules and headers for each content type, and tidy the cache key.
  5. Enable TLS and HTTPS.
  6. Turn on security features, starting in monitoring mode where possible, then tighten.
  7. Add purge steps to your publishing or deployment process.
  8. Test as described above.
  9. Document everything, including how to bypass the CDN in an emergency.

Is multi-CDN worth considering?

Some critical sites use more than one CDN so that an outage at one provider does not take them down. It adds complexity and cost, so most small and mid-size sites do not need it.

A worked example

Imagine a small online shop with a server in one country and customers in several. Product images are large and load from the origin, so pages feel slow abroad. The team places a CDN in front, caches images and stylesheets with long TTLs and fingerprinted filenames, and caches category pages briefly. The basket and checkout are excluded. After testing with two accounts to confirm baskets are not shared, they see faster image loading and calmer origin traffic during a sale.

FAQ

What does a CDN do for a website?

A CDN keeps copies of your files on servers around the world and serves each visitor from a nearby one. That reduces loading time, lowers the load on your main server and often adds protection against attacks.

Do I need a CDN for a small website?

Not always. A small, light site whose visitors are close to the server may gain little. A CDN helps most when visitors are spread out, pages have heavy images, traffic comes in spikes or you want extra protection.

Why do I still see old content after updating my site with a CDN?

The CDN is probably serving a cached copy that has not expired. Purge the affected files or pages, use shorter TTLs for content that changes often, and use versioned filenames for static assets.

Is a CDN the same as web hosting?

No. Hosting runs your site and stores its real data. A CDN is a layer in front of your hosting that delivers cached copies from locations near your visitors.

Related reading

Next steps

Sort your site's content into static, public and personalised, then check how your current cache headers are set. That tells you what a CDN could safely do for you. If you would like help with setup, caching rules or performance, see our cloud services or contact us.

More from the blog

Let's build together

Ready to take your business to the next level?

Tell us what you need. We will reply within one business day with next steps.