CDN distributes content via edge servers around the world. Lower latency, higher availability.
Principle¶
Edge servers cache content close to users. Tokyo -> edge in Tokyo instead of origin in Prague.
What to Cache¶
- Static files (CSS, JS, images) — long TTL
- HTML — short TTL / stale-while-revalidate
- API — read-only, public only
- Video/audio — ideal use case
Cache-Control¶
Static assets¶
Cache-Control: public, max-age=31536000, immutable
HTML¶
Cache-Control: public, max-age=300, stale-while-revalidate=86400
Never¶
Cache-Control: no-store
Providers¶
- Cloudflare — free, DDoS, Workers
- CloudFront — AWS, Lambda@Edge
- Fastly — real-time purging
- Vercel/Netlify — JAMstack
CDN = Speed + Availability¶
A standard for any public-facing website.