How CDN Caching Speeds Up Websites

Photo: Bibek ghosh / Pexels
A visitor in Sydney loading a website hosted in Virginia would, without help, wait for data to cross roughly 16,000 kilometers (9,900 miles) of undersea cable and back. A content delivery network (CDN) avoids that entirely by storing a copy of the site's static files on servers physically close to Sydney, so the round trip shrinks to a few hundred kilometers instead of half the globe. That distance reduction, not some clever compression trick, is the core of why CDNs make websites feel faster, and understanding the mechanics behind it explains almost everything else about how modern web infrastructure is built.
Distance is latency, and latency is unavoidable physics
Data traveling through fiber-optic cable moves at roughly two-thirds the speed of light in a vacuum, because light slows down when it passes through glass instead of empty space. That sounds fast in absolute terms, but over long distances it adds up in ways that no amount of software optimization can undo. A round trip between Sydney and Virginia carries an unavoidable latency floor of tens of milliseconds purely from the speed of light, before any server processing time, database query, or rendering work is even counted.
This is the single fact that makes CDNs necessary rather than merely convenient. No matter how efficiently a server's backend code runs, if the server itself sits 16,000 kilometers away from the person requesting a page, every request pays a physical distance tax that server-side optimization cannot touch. A CDN's edge servers (machines positioned in dozens or hundreds of cities worldwide, each holding a cached copy of a site's static content) cut that physical distance dramatically for most visitors, converting a long-haul international trip into a short local one.
Cloudflare's own network map, one of the largest CDN footprints in the industry, describes coverage across more than 300 cities globally, spanning every populated continent (Cloudflare, 2026). Akamai, one of the oldest commercial CDN providers, reports an edge network of more than 4,200 points of presence spread across over 130 countries, built up over more than two decades of expansion (Akamai/Forbes, 2026). These aren't small regional caches, they're planet-spanning networks specifically engineered to put a server within a short physical hop of nearly every internet-connected person on Earth.
Companies like Cloudflare and Akamai operate points of presence in hundreds of cities, and when a browser requests a file, DNS routing (specifically a technique called anycast, which lets many servers worldwide share the same IP address) automatically directs the request to whichever edge server is geographically or topologically closest to the visitor, not to the website's origin server. Think of anycast the way you'd think of dialing a single national customer-service number that automatically connects you to the nearest call center: you dial one number, but the network quietly routes you to whichever physical location can answer fastest, and you never have to know or care which one that is.
What actually gets cached, and why it matters
CDNs cache static assets: images, CSS files, JavaScript bundles, videos, and fonts, content that's identical for every visitor and doesn't change based on who's asking. Each cached file carries an HTTP header, typically Cache-Control, that tells the CDN and the visitor's browser how long they're allowed to serve that copy before checking back with the origin server for an update. This single header is arguably the most important piece of plumbing in the entire CDN system, because it's the mechanism that turns "store a copy somewhere" into a coordinated, predictable caching strategy across millions of requests.
According to MDN Web Docs, the max-age directive on a Cache-Control header states the maximum amount of time, in seconds, that a fetched response is allowed to be reused from the moment the request was made (MDN Web Docs, 2026). A related directive, s-maxage, does something subtly different: it tells shared caches specifically, meaning CDNs and proxy servers rather than an individual visitor's browser, how long they may keep serving a cached copy, and it overrides max-age for those shared caches when both are present (MDN Web Docs, 2026). That distinction lets a site operator set one cache lifetime for the CDN layer and a different, often shorter, one for the browser sitting on a visitor's laptop or phone.
Dynamic, personalized content, like a logged-in user's account dashboard, a shopping cart, or a page showing a visitor's name, generally can't be cached the same way, since the content differs per request and per person. Caching it anyway would mean showing one visitor another visitor's private data, which is why CDNs are careful to distinguish cacheable static assets from request-specific dynamic responses. This is why CDNs are most effective for content-heavy sites like news publishers and e-commerce product catalogs, where the bulk of what loads (images, product photos, layout scripts, stylesheets) is identical for every visitor, while the smaller personalized pieces, like a "Welcome back" banner or a cart total, still travel to the origin server on every request.
Some CDNs, and increasingly Cloudflare and Fastly among them, also offer edge compute layers that let a small piece of custom code run at the edge server itself, close to the visitor, rather than at the origin. That's a separate capability from static caching, closer to running a lightweight function than storing a file, but it builds on the same core idea: doing more work physically closer to the person who requested it.
Cache hits, misses, and the "cold" problem
Every cached request falls into one of a small number of categories, and the vocabulary around them shows up constantly in server logs, CDN dashboards, and performance-debugging conversations.
- A cache hit happens when the requested file is already stored on the nearby edge server, and it can be served in a few milliseconds without contacting the origin server at all. This is the fast path, and it's the entire point of running a CDN in the first place.
- A cache miss happens when the edge server doesn't have the file yet, either because no one nearby has requested it recently or because it expired, so the edge server fetches it from the origin server once, caches it locally, and serves it to all subsequent nearby visitors from that point forward.
- A cold cache describes an edge location that has never served a given file (or hasn't served it recently enough to still hold a copy), meaning the very first visitor to hit that location experiences something close to the uncached, full-distance latency, before the file gets warmed up for everyone who follows.
- Cache invalidation happens when a website owner updates a file and needs the CDN to discard the old cached version immediately rather than waiting for the configured expiration time to pass naturally. This is typically triggered manually through a CDN dashboard or API call, called a "purge."
- Origin shielding is a technique where CDNs designate one edge location, sometimes called a shield or a mid-tier cache, to always check with the origin server first on a cache miss, reducing the number of direct hits the origin receives even when many different edge locations around the world are experiencing cache misses simultaneously.
The cold-cache problem matters most for low-traffic sites and rarely requested files. A page that gets ten visitors a month from ten different countries may see almost every single request treated as a cache miss at its local edge location, simply because no other nearby visitor has requested that exact file recently enough to keep it warm. High-traffic sites don't have this problem in practice, because enough requests flow through each regional edge server that files stay continuously cached.
The economics behind why CDNs exist at all
Storing copies of files on servers scattered across the globe is not free, and understanding the economic logic behind CDNs explains why they're built the way they are rather than some alternative design.
Every time an edge server serves a file from cache instead of forwarding the request to the origin, it saves the origin server compute cycles, bandwidth, and, for cloud-hosted origins billed by data transfer, real money. A viral article or a product page that suddenly gets linked from a major platform can generate a spike in traffic that would otherwise overwhelm a single origin server, but with a CDN in front of it, the vast majority of that spike gets absorbed by edge caches that were never touching the origin server at all after the first request.
This is sometimes called the "thundering herd" problem in distributed systems: without caching, a sudden burst of near-identical requests all hit the same backend at once and can knock it offline. A CDN acts as a shock absorber, collapsing what could be millions of near-simultaneous identical requests down into a handful of actual origin fetches, one per edge location, with everyone else served from the cache that first fetch created.
Fastly, a CDN provider that has focused its network architecture around fewer but more powerful points of presence placed near major internet exchange points rather than maximizing raw city count, illustrates that there isn't just one correct way to build this kind of network (Fastly, 2026). Cloudflare and Akamai lean toward broader geographic distribution with very high point-of-presence counts, while Fastly's strategy emphasizes fewer, more capable nodes concentrated near high-density internet exchange points. Both approaches are trying to solve the same underlying physics problem: minimizing the distance and number of network hops between a request and the server that answers it, just with different tradeoffs between raw coverage and per-node capability.
| Cache Layer | Typical TTL (Time to Live) | Where It Lives | Effect on Hit Rate |
|---|---|---|---|
| Browser cache | Minutes to weeks, set by Cache-Control: max-age |
The visitor's own device | Eliminates the network trip entirely for repeat visits to the same device |
| CDN edge cache | Minutes to days, often set independently via s-maxage |
Regional edge servers close to visitors | Highest-impact layer for first-time and cross-device visitors; shared across every nearby user |
| Origin server cache | Seconds to hours, application-level (e.g., database query cache) | The website's own backend infrastructure | Speeds up cache misses that do reach the origin, but does nothing for network distance |
The browser cache and CDN edge cache work together to serve most repeat requests without ever reaching the origin server; the origin cache only matters for the requests that get through.
What people get wrong about CDNs
A common misconception is that a CDN makes a website's own server code run faster. It doesn't: a CDN reduces the physical distance data has to travel and offloads static file serving, but it does nothing for how quickly a database query executes, how efficiently a server-side script processes a request, or how well an application is architected. Slow backend code is still slow, regardless of CDN use, in the same way that a faster highway to a restaurant doesn't make the kitchen cook any quicker. If a site's core problem is an inefficient database query running on every page load, adding a CDN in front of it will speed up the images and stylesheets while leaving the actual slow part completely untouched.
Another misconception is that adding a CDN is a one-time fix that requires no further attention. In practice, cache headers have to be configured correctly for each type of content, and a misconfigured cache duration can serve visitors outdated content for hours (if the duration is set too long relative to how often the content changes) or provide almost no caching benefit at all (if the duration is set too short to ever accumulate meaningful cache hits). Site operators who deploy a CDN and never revisit their caching rules often end up either serving stale content after updates or getting far less benefit from the CDN than they paid for.
A third, subtler misconception is that CDNs are only useful for large, high-traffic websites. While the biggest efficiency gains do show up at scale, because more traffic means more cache hits per file cached, even a modest site with an international audience benefits from the pure distance reduction on every single visitor's first load, cache hit or miss. A visitor in a different country loading even a completely cold cache still connects to a nearby edge server over a shorter network path than they would connecting directly to a distant origin, which typically improves the initial TCP and TLS handshake time even before any file caching comes into play.
A fourth misconception worth addressing directly: some site owners assume that because a CDN caches "the internet," it somehow also protects against every kind of attack or outage. CDNs do commonly bundle security features like DDoS mitigation and web application firewalls, since the same distributed edge network that's good at absorbing traffic spikes for performance reasons is also naturally well positioned to absorb malicious traffic spikes. But that security layer is a separate product decision from caching itself, not an automatic side effect of storing static files closer to visitors, and turning on a CDN's caching does not by itself turn on every security feature the provider offers.
How to check whether your CDN setup is actually working
For anyone responsible for a website's performance, verifying that caching is actually delivering the expected benefit is straightforward but frequently skipped. Most CDN providers expose an X-Cache or similarly named response header (the exact name varies by provider) on every request, indicating whether that specific request was served as a hit or a miss.
Watching this header across a sample of requests from different geographic regions reveals whether a site's cache configuration is doing its job. A site with a healthy caching setup should show the overwhelming majority of static-asset requests coming back as cache hits after the first few visitors from any given region have warmed up the local edge cache. A site showing a high proportion of misses on files that shouldn't be changing frequently, like a logo image or a CSS bundle, usually points to a Cache-Control header that's set too aggressively short, or to cache invalidation rules that are purging content more often than necessary.
Browser developer tools also make this visible without needing server-side log access. Opening the Network tab and reloading a page shows, for each resource, whether it was served "from disk cache," "from memory cache," or fetched fresh over the network, giving a quick read on whether the browser-level cache (the fastest possible layer, since it skips the network entirely) is working as intended alongside the CDN layer.
The takeaway
CDN caching works because it attacks the one thing no amount of clever code can fix: the physical distance data has to travel, governed by the fixed speed at which light moves through fiber-optic cable. By storing copies of static files on servers scattered across the globe, in hundreds of cities for providers like Cloudflare and Akamai, and routing each visitor to the nearest one through anycast DNS, a CDN turns a slow, long-distance round trip into a short, local one. Getting the details right, correctly configured Cache-Control headers, sensible cache invalidation, and an honest understanding of what a CDN cannot fix, is what separates a setup that delivers this benefit reliably from one that only looks like it's helping.
Read next:
FAQ
Q: What is the difference between a cache hit and a cache miss?
A cache hit means the requested file is already stored on the nearby CDN edge server and gets served in a few milliseconds. A cache miss means the edge server has to fetch the file from the origin server first, adding latency for that one request before the file is cached locally for everyone nearby who requests it afterward.
Q: Can a CDN cache dynamic, personalized web pages?
Generally not directly, since dynamic content differs per user or per request and caching it could expose one visitor's data to another. CDNs are most effective for static assets like images, CSS, JavaScript, and video that are identical for every visitor, while personalized content typically still routes to the origin server.
Q: How does a CDN know which server is closest to a visitor?
CDNs typically use anycast DNS routing, a technique that lets many edge servers around the world share the same IP address, automatically directing each visitor's request to the nearest or fastest-responding location based on network routing, without the visitor's device needing to know which physical server it ends up talking to.
Q: Does using a CDN improve backend or database performance?
No. A CDN reduces the distance static files travel and offloads that traffic from the origin server, but it has no effect on server-side code execution, application logic, or database query speed, which remain entirely the origin server's responsibility.
Q: What does the Cache-Control header actually control?
The Cache-Control HTTP header tells browsers and CDNs how long a fetched response can be reused before it needs to be checked against the origin server again, using directives like max-age for general caching duration and s-maxage to set a separate duration specifically for shared caches like CDNs (MDN Web Docs, 2026).
Q: Why do some visitors still get a slow first load even with a CDN in place?
If a file hasn't been requested recently from a particular geographic region, the local edge server's cache for that file is "cold," meaning the very first visitor from that region experiences something close to the full uncached latency while the edge server fetches and caches a fresh copy from the origin, before every subsequent nearby visitor benefits from the now-warm cache.
Follow new articles
Add SciHub101 to your feed reader to see new science and technology stories.
About the Author
SciHub101 is an independent science and technology publication founded and edited by Buğra Sözeri, a software engineer and app developer based in Türkiye. AI tools assist with drafting and research. Source documentation in the existing archive is uneven, and articles are being reviewed and corrected. The Editorial Team byline identifies editorial responsibility; it does not certify specialist or independent human review. Where we compare products, anything built by our own team is labelled as such — see the editorial guidelines and About page for how corrections and disclosures work.
Related Articles



What Is Hono? Edge-First Web Framework
Hono is a fast, tiny TypeScript web framework that runs on Cloudflare Workers, Deno, Bun, and Node. How it works and when to use it.

What Is Drizzle ORM? TypeScript SQL Builder
Drizzle ORM is a lightweight, type-safe TypeScript ORM with SQL-like syntax. Schema, queries, migrations, and comparison with Prisma.

Largest Airports in the World by Size and Passenger Traffic
The largest airport can mean land area, terminal size, runways, or passengers. This guide ranks all four and explains why the answers never match.

Largest Dams in the World Explained: Height, Volume, and Power
The largest dam changes depending on whether you rank by height, reservoir, concrete volume, or hydroelectric output. Here is the science behind each record.