A content delivery network (CDN) is a globally distributed network of proxy servers that cache and serve content from locations closer to the user. Instead of every request traveling to a single origin server in us-east-1, the CDN routes it to the nearest edge Point of Presence (PoP), where cached content is served in milliseconds.
When you load a page on Vercel, Netlify, or Cloudflare Pages, every static asset — JavaScript bundles, CSS files, images, fonts — hits a CDN edge before reaching your browser. The HTML itself might be served from the edge too, via ISR (Incremental Static Regeneration) or edge-rendered responses. The key insight: the CDN isn't optional anymore. It's the default delivery mechanism for the modern web.
Here is what a CDN request flow looks like at the edge — a service worker running on every request, checking cache, and falling back to origin:
addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request: Request): Promise<Response> {
const url = new URL(request.url);
const cacheKey = new Request(url.toString(), request);
const cache = caches.default;
let response = await cache.match(cacheKey);
if (response) {
console.log("Cache HIT for", url.pathname);
return response;
}
console.log("Cache MISS for", url.pathname);
response = await fetch(request);
if (response.status === 200) {
const cloned = response.clone();
const headers = new Headers(cloned.headers);
headers.set("cache-control", "public, max-age=31536000, immutable");
const cached = new Response(cloned.body, { status: cloned.status, headers });
ctx.waitUntil(cache.put(cacheKey, cached));
}
return response;
}This pattern — cache.match, origin fetch on miss, cache.put in the background — is the fundamental building block of every CDN edge worker. Cloudflare Workers, Deno Deploy, and Vercel Edge Functions all use the same mental model: intercept the request, serve from cache or origin, optionally transform the response.