How CDNs work and when you actually need one
CDN edge nodes, PoP locations, origin server, cache hit vs miss, CDN for static assets, CDN for HTML, edge computing, CDN configuration, Cache-Control with CDN
Content Delivery Networks
A CDN caches your assets at edge nodes globally. A user in Singapore hitting a CDN edge node in Singapore gets the file in ~5ms instead of ~200ms from an origin server in the US. For static assets, this is purely a physics win.
CDN caching is controlled by the same Cache-Control headers your origin sends. Add s-maxage to set a separate TTL for CDN caches:
# Public caches (CDN) cache for 1 year; browsers cache for 1 day
Cache-Control: public, max-age=86400, s-maxage=31536000
# HTML: never cache at CDN (need fresh content), revalidate in browser
Cache-Control: no-cache, s-maxage=0Modern CDNs (Cloudflare, Fastly, Vercel Edge) also run edge functions — serverless functions that execute at the edge node, reducing API TTFB to under 50ms globally.
When do you need a CDN? Nearly always for static assets. For HTML, a CDN makes sense when your content is cacheable (blogs, marketing sites) but adds complexity for dynamic applications (logged-in user state, personalization).
CDNs also provide DDoS protection, automatic TLS certificates, and HTTP/3 support without server configuration. Cloudflare's free tier covers most static sites entirely.
