Cloud & DevOps

What Is a CDN and Does Your Website Need One?

November 30, 2026 · 11 min read

What Is a CDN and Does Your Website Need One?

What is a CDN? A content delivery network is a group of servers spread across many cities that keeps copies of your website's files close to your visitors. When someone in Karachi opens a site hosted in London, a CDN can serve images, scripts and even whole pages from a nearby location instead of making every request cross continents. The result is faster pages, less load on your own server and better protection against traffic spikes and attacks.

CDNs now carry a large share of the web. The HTTP Archive's 2025 Web Almanac found that 35% of HTML documents on mobile pages are served through a CDN, up from about 20% in the 2019 edition, alongside 52% of resources on site subdomains and 71% of third-party resources. This guide explains how a CDN works, what it does beyond caching, whether your website needs one, and how to set caching headers so it actually helps.

How a CDN Works, Step by Step

  1. The visitor requests your site. Your domain's DNS points to the CDN, which usually uses anycast routing so the request reaches the nearest location, called a point of presence (PoP).
  2. The PoP checks its cache. If it has a fresh copy of the file, that is a cache hit, and the response goes straight back to the visitor in milliseconds.
  3. On a cache miss, the PoP fetches the file from your server, known as the origin, returns it to the visitor and stores a copy.
  4. The copy stays fresh for as long as your caching headers allow (the time to live, or TTL). Later visitors in that region get the cached copy.
  5. When content changes, the CDN either revalidates with the origin after the TTL or you purge the old copy immediately.
TermMeaning
Point of presence (PoP)A CDN data centre in a particular city
OriginYour own server or storage bucket that holds the master copy
Cache hit ratioThe share of requests answered from the CDN without contacting the origin
TTLHow long a cached copy counts as fresh
PurgeRemoving content from the CDN's cache before its TTL expires
Origin shieldAn extra caching layer so PoPs do not all hit your origin at once

What a CDN Does Beyond Caching

  • Faster connections: the CDN completes the TLS handshake close to the visitor and supports modern protocols such as HTTP/2 and HTTP/3. Cloudflare's 2025 Year in Review also found that 52% of human web traffic it handled used post-quantum encryption by early December, up from 29% at the start of the year.
  • Compression and image optimisation: many CDNs compress text with Brotli and resize or convert images to modern formats such as WebP and AVIF on the fly.
  • DDoS protection: a global network absorbs floods of traffic that would knock a single server offline.
  • Web application firewall and bot management: blocks common attacks and abusive bots before they reach your application.
  • Edge functions: run small pieces of code at each PoP for redirects, personalisation or authentication, as explained in our guide to edge computing.
  • Load balancing and failover: spread traffic across several origins and route around one that fails; see our guide to load balancing.

How Much Faster Does a CDN Make a Site?

The physics is simple. Light in optical fibre covers roughly 200 kilometres per millisecond, and real cable routes are longer than a straight line, so a round trip between London and Karachi typically takes somewhere around 120 to 150 milliseconds. Opening a new HTTPS connection needs about three round trips before the first byte of a page arrives: one for the TCP handshake, one for the TLS handshake and one for the request itself. That is roughly 400 milliseconds of waiting before your server has done any work at all. These are estimates, and actual figures depend on networks and routing.

If a CDN location in the same city answers with a round trip of around 10 milliseconds, the same three steps take about 30 milliseconds, and a cache hit means your origin is not involved at all. Multiply that by the dozens of files a typical page loads and the difference becomes obvious, especially on mobile networks. HTTP/3 helps further by combining the connection and encryption handshakes, and CDNs are usually the easiest way to switch it on.

Does Your Website Need a CDN?

Most websites benefit, and many CDNs have free or very cheap plans for small sites. A CDN is close to essential if:

  • Your visitors are spread across countries or continents.
  • Your pages are heavy with images, video or downloads.
  • You get traffic spikes from campaigns, launches or seasonal sales.
  • You run an online shop, where every extra second of loading costs conversions.
  • You have been targeted by bots, scrapers or denial-of-service attacks.

It matters less for an internal tool used in one office, or a small site whose visitors are all near the server, but even then a CDN's free TLS, compression and attack protection are worth having. Speed also feeds search rankings through Core Web Vitals, which is why a CDN appears in our technical SEO checklist and our guide on how to make a website load faster.

Set Cache-Control Headers So the CDN Can Help

A CDN can only cache what your origin allows it to cache. The rules live in the Cache-Control header, defined in the HTTP caching standard RFC 9111. The script below picks a header for each type of response, then simulates a busy hour to show what a short CDN cache does for your origin:

// cdn-cache.mjs: choose Cache-Control headers, then see what a CDN does with them

// 1. One rule per type of response
function cacheControl(path, { loggedIn = false } = {}) {
  if (/\.[0-9a-f]{8,}\.(js|css|woff2|avif|webp|png)$/.test(path)) {
    return "public, max-age=31536000, immutable"; // fingerprinted file: the name changes when the content does
  }
  if (path.startsWith("/api/") || loggedIn) return "private, no-store"; // personal data: never in a shared cache
  if (!path.includes(".") || path.endsWith(".html")) {
    return "public, max-age=0, s-maxage=300, stale-while-revalidate=60"; // browsers revalidate, CDN keeps 5 minutes
  }
  return "public, max-age=86400"; // other static files: one day
}

for (const p of ["/", "/pricing", "/assets/app.3f9c2a1b.js", "/api/cart", "/favicon.ico"]) {
  console.log(p.padEnd(26), cacheControl(p));
}

// 2. Simulate one busy hour: 36,000 requests for the home page, spread over 3 edge locations
const ttlSeconds = 300; // s-maxage from the rule above
const expiresAt = { london: 0, frankfurt: 0, karachi: 0 };
const pops = Object.keys(expiresAt);
let hits = 0;
let originFetches = 0;
for (let i = 0; i < 36000; i++) {
  const t = i / 10; // one request every 0.1 seconds
  const pop = pops[i % pops.length];
  if (t < expiresAt[pop]) hits++;
  else { originFetches++; expiresAt[pop] = t + ttlSeconds; }
}
console.log(`origin fetches: ${originFetches} of 36000, hit ratio ${((100 * hits) / 36000).toFixed(2)}%`);

Running it with Node.js prints:

/                          public, max-age=0, s-maxage=300, stale-while-revalidate=60
/pricing                   public, max-age=0, s-maxage=300, stale-while-revalidate=60
/assets/app.3f9c2a1b.js    public, max-age=31536000, immutable
/api/cart                  private, no-store
/favicon.ico               public, max-age=86400
origin fetches: 36 of 36000, hit ratio 99.90%

Four directives do most of the work:

  • immutable with a one-year max-age for fingerprinted files whose names change when their content changes, such as app.3f9c2a1b.js. Modern build tools such as Vite and Next.js create these names for you.
  • s-maxage sets how long shared caches such as CDNs keep a copy, separately from browsers. Here browsers always check for fresh HTML, while the CDN keeps it for five minutes.
  • stale-while-revalidate lets the CDN serve a slightly old page while it fetches a new one in the background, so no visitor waits on the origin.
  • private, no-store keeps personal responses such as carts, account pages and API data out of shared caches entirely.

The simulation shows the payoff: with just a five-minute cache on the home page, 36,000 requests in an hour across three locations turn into only 36 requests to the origin, a 99.9% hit ratio. Your server does a tiny fraction of the work, and it no longer matters much whether it runs Nginx or Apache.

Check What Your CDN Is Doing

Headers tell you whether a response came from the cache. Look for Age (how long the copy has been cached) and the CDN's own status header, such as cf-cache-status or x-cache. This script checks headers and timing for any URL and shows how to purge a page after a deploy; our guide to Linux commands explains curl and grep if they are new to you.

#!/usr/bin/env bash
# check-cdn.sh: see what the CDN did with a URL (pass the URL as the first argument)
URL="${1:-https://www.example.com/}"

# Caching headers: look for Age, Cache-Control and the CDN's own status header
curl -sI "$URL" | grep -iE '^(cache-control|age|cf-cache-status|x-cache|server|alt-svc):'

# Time to first byte from where you are now
curl -s -o /dev/null -w 'ttfb=%{time_starttransfer}s total=%{time_total}s\n' "$URL"

# Purge one URL after a deploy (Cloudflare API shown; other CDNs have similar endpoints)
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/purge_cache" \
  -H "Authorization: Bearer ${CF_API_TOKEN}" \
  -H "Content-Type: application/json" \
  --data "{\"files\":[\"${URL}\"]}"

Purge by exact URL or cache tag rather than "purge everything", which sends a wave of traffic to your origin at the worst possible moment.

Choosing a CDN

ProviderKnown forGood fit
CloudflareVery large network, generous free plan, security and edge functions in one platformMost websites, from small businesses to large platforms
Amazon CloudFrontTight integration with S3, load balancers and LambdaApplications already on AWS
FastlyInstant purging, programmable caching and edge computePublishers, ecommerce and developer-heavy teams
AkamaiOne of the oldest and largest networks, strong enterprise securityLarge enterprises, media and banking
Bunny.netSimple, low-cost pay-as-you-go pricingSmall sites, video and file delivery on a budget

Compare the number and location of PoPs where your customers live, pricing for bandwidth and requests, security features, purge speed, logging and how easily the CDN fits your hosting. Cloudflare alone says its network spans more than 330 cities and reaches about 95% of the world's internet-connected population within 50 milliseconds.

Common CDN Mistakes

  • Caching personal pages. A cached account page shown to the wrong visitor is a data breach. Mark personalised responses private.
  • Cookies that break caching. Many CDNs skip caching responses that set cookies; keep cookies off static content.
  • Query strings that fragment the cache. Tracking parameters can create thousands of copies of one page; configure the cache key to ignore them.
  • Forgetting the origin's security. If attackers can reach your origin directly, they bypass the CDN's protection. Allow traffic only from the CDN.
  • Treating the CDN as infallible. On 18 November 2025 a faulty bot-management configuration file caused a major Cloudflare outage that took many well-known sites offline for hours. Critical services should have a documented fallback.

A CDN is one of the cheapest performance and security upgrades available, and it works with almost any type of web hosting.

Frequently Asked Questions

What is a CDN in simple terms?

A CDN is a network of servers in many locations that stores copies of your website's content and delivers it to each visitor from the closest location, making the site faster and more reliable.

Is a CDN the same as web hosting?

No. Your host stores the original site and runs its code. A CDN sits in front of the host, caching and delivering content and filtering traffic.

Does a CDN improve SEO?

Indirectly, yes. Faster loading improves user experience and Core Web Vitals, which Google uses as signals, and better uptime keeps your pages available to crawlers.

Can a CDN cache dynamic pages?

Yes, if they are the same for everyone, using short TTLs and stale-while-revalidate. Personalised pages should not be cached in shared caches, though edge functions can assemble them from cached parts.

Is Cloudflare a CDN?

Yes. Cloudflare is one of the largest CDNs, and it also provides DNS, DDoS protection, a web application firewall, edge functions and other services on the same network.

How much does a CDN cost?

Many CDNs offer free plans for small sites. Paid plans usually charge by bandwidth and requests, or a flat monthly fee, so costs scale with traffic.

Speed Up Your Website

We set up CDNs, caching rules and edge functions, and tune origins so your pages load fast for every visitor. Contact our team to make your site faster and harder to knock offline.

Want this built for you?

Our team offers Website Deploy On Vercel — get a free quote.

View Services