LineLapse BlogMake your own →
← All posts

How does a CDN make websites faster?

#networking#performance#infrastructure

Picture a bakery that only has one shop, in one city, but ships its bread everywhere. A customer three countries away places an order, and a loaf has to travel the whole distance before it arrives stale and late. Now picture the same bakery with small ovens in a hundred cities, each stocked with the same recipe, baking fresh bread close to wherever the order comes from. That's the difference a CDN makes for a website — it puts copies of your content close to the people asking for it, instead of making every request travel back to one far-away server.

How Does a CDN Work?proximity, caching, zero wasted distanceYouDistant ServerCDNContent Delivery NetworkPoP — LondonPoP — MumbaiPoP — São PauloYouNearest PoPCached Contentimages, scripts, stylesInstant!ProximityCachingshorter distancedata pre-loadedDynamic ContentOrigin ServerEverywhere Fastzero wasted distancelong tripfast routefastest route
▶ Watch it draw

The problem: distance costs time

Every request to a website has to physically travel — through cables, routers, and exchange points — from the visitor's device to the server that holds the content. Data moves fast, but it isn't instant, and the internet's plumbing adds real delay at every hop. A visitor in Sydney loading a site hosted in Virginia is waiting on a round trip that crosses an ocean and half a continent, twice: once to ask, once to get the answer.

That delay is called latency, and it stacks up. A single page can trigger dozens of requests — the HTML, then images, scripts, and stylesheets — and if every one of them has to cross the planet, the page feels sluggish no matter how powerful the original server is. Distance, not raw computing power, is often the real bottleneck.

What a CDN actually is

A content delivery network is a set of servers spread across many physical locations around the world, each holding a cached copy of a site's content. These are usually called edge servers, because they sit at the "edge" of the network, as close as possible to real visitors.

When someone requests a page, the CDN routes them to whichever edge server is nearest — often using DNS to answer with a different server address depending on where the request came from. That nearby server can answer immediately from its own copy, without ever contacting the original server, which is usually called the origin.

The bread bakery only works if the ovens actually have fresh loaves ready before anyone orders. A CDN solves this the same way: it pre-positions copies of the origin's content ahead of time, or fetches and stores a copy the first time it's requested, so the next nearby visitor gets it instantly.

Caching: what gets copied, and for how long

Not everything on a website behaves the same way, so a CDN treats content differently depending on how often it changes:

  • Static assets — images, videos, fonts, CSS, and JavaScript files — rarely change once published, so CDNs cache these aggressively, sometimes for days or weeks.
  • Semi-dynamic content, like a blog post or product page, might update occasionally, so it's cached with a shorter expiry and refreshed periodically.
  • Fully dynamic content, like a personalized dashboard or a live stock price, usually skips the cache entirely and goes straight to the origin, because caching the wrong copy for the wrong person would be worse than no caching at all.

The origin server tells the CDN how long to keep a cached copy through simple instructions in the response headers. When that time runs out, or the origin pushes an update, the CDN quietly fetches a fresh copy the next time it's needed — the visitor never sees the swap happen.

Speed isn't the only benefit

Once a network of servers sits between every visitor and your origin, a few other things fall into place almost for free. A traffic spike — a product launch, a viral post — gets absorbed by dozens of edge servers instead of slamming one machine, because most requests never reach the origin at all. And because the origin is now hidden behind that layer, it's much harder for someone to overwhelm it directly with a flood of malicious traffic; the CDN can also filter obviously bad requests before they get anywhere near your actual server.

Why this matters even for a small site

It's easy to assume CDNs are only for huge, global companies, but the core idea scales down just fine. Even a modest site with visitors spread across a few countries benefits from cutting the distance data has to travel — and since most of the web's weight is in static assets, even a single-server app loads noticeably faster just by letting a CDN handle those files instead of serving them from the origin directly.

The takeaway

A CDN's whole idea is simple: don't make every visitor's request travel all the way to one distant server when a nearby copy will do. By caching content at edge servers spread around the world, it cuts the physical distance data has to travel, spreads out sudden traffic spikes, and adds a layer of protection in front of the origin — all without the visitor ever noticing anything happened except that the page loaded fast.


This explainer was made with LineLapse — type a topic, get a hand-drawn video. Make your own →