The Problem CDNs Solve

Physics limits how fast data can travel. Light through fibre covers roughly 200km per millisecond. A user in London requesting an image from a server in Mumbai adds ~70ms of latency just for the round trip — before any processing. With a CDN edge node in London, that same image is served in ~5ms.

Multiply this by every asset on a page (dozens of images, CSS, JS files) and the difference between a CDN-served and non-CDN-served site is often 2–5 seconds of load time.

How a CDN Request Works

  1. First request (cache miss): User in London requests example.com/logo.png. DNS resolves to the nearest CDN edge node (also London). Edge node does not have the file — it fetches from origin server (Mumbai), caches it locally, returns it to the user.
  2. Subsequent requests (cache hit): Next user in London requests the same file. Edge node serves it directly from its cache — origin server never contacted. Response time: ~5ms vs ~70ms.
  3. Cache expiry: After the TTL expires (e.g. 24 hours), the next request triggers a fresh fetch from origin.

CDN Benefits

  • Speed: Assets served from nearest edge node — lower latency for all global users
  • Origin offload: 80–95% of static asset requests never reach your origin server
  • Scalability: CDN absorbs traffic spikes — if your site goes viral, CDN serves the load
  • DDoS protection: Distributed edge absorbs attack traffic; hides origin IP
  • Availability: If origin is down, cached content may still be served
  • HTTPS termination: CDN handles TLS at the edge — reduces TLS overhead on origin

Cache Control Headers

You control what CDNs cache and for how long via HTTP response headers from your origin:

HeaderExampleEffect
Cache-Controlpublic, max-age=31536000CDN and browsers cache for 1 year
Cache-Controlno-storeNever cache — always fetch from origin
Cache-Controlprivate, max-age=3600Browser caches, CDN does not
ETag"abc123"Fingerprint for conditional requests
Surrogate-Controlmax-age=86400CDN-specific TTL (overrides Cache-Control for CDN)

Cache Invalidation Strategies

  • URL versioning (best): Append content hash to filename — app.a3f4b2.js. New deploy = new filename = cache miss automatically. Old URL cached indefinitely.
  • Query string: logo.png?v=2 — simple but some CDNs ignore query strings by default
  • Manual purge: Use CDN API/dashboard to purge specific URLs or entire cache on deploy
  • Short TTL: Set max-age=300 — changes propagate within 5 minutes. Trade-off: more origin hits.

⚠️ Don't Cache Personalised or Private Content

Only cache content that is the same for all users. Never put Cache-Control: public on responses containing user-specific data (user profiles, cart contents, authenticated pages). Set Cache-Control: private or no-store for these.

Popular CDN Providers

CDNPoPsFree TierBest For
Cloudflare300+Yes (unlimited bandwidth)Most sites — easiest setup
AWS CloudFront450+1TB/mo first yearAWS-native apps (S3, EC2)
Fastly80+NoSub-second purge, edge compute
BunnyCDN120+No (cheap — $0.01/GB)Budget-friendly, easy pricing
Vercel EdgeCloudflare-backedYesNext.js / frontend frameworks

💡 Start with Cloudflare Free

Cloudflare's free tier provides CDN, DDoS protection, and automatic HTTPS for any domain — just change your DNS nameservers. It is the fastest path from zero CDN to production-grade delivery, with no bandwidth limits and no credit card required.

How We Research and Update This Guide

We test the underlying formula or workflow, compare outputs with reliable references, and revise examples whenever the page content changes.

  • The workflow or formula is tested directly in the tool and compared against independent reference examples.
  • Examples are kept practical so readers can verify the result without hidden assumptions.
  • Pages are revised whenever the interface, calculation flow, or surrounding guidance materially changes.

Frequently Asked Questions — CDN