CDNs serve content from locations close to users. This guide covers configuring CDNs for optimal performance.
How CDNs Work#
User (Tokyo) ─────┐
│
User (NYC) ───────┼──> Edge Server ──> Origin Server
│ (Cached)
User (London) ────┘
Cloudflare Configuration#
Cache Rules#
Loading code block...
Page Rules#
Loading code block...
Cache Headers#
Loading code block...
Cache Invalidation#
Loading code block...
Cache Tags#
Loading code block...
Performance Tips#
- Use immutable for versioned assets:
max-age=31536000, immutable - Enable Brotli compression: Smaller file sizes
- Use stale-while-revalidate: Better perceived performance
- Cache API responses: Even short TTLs help
- Monitor cache hit ratio: Target >90% for static content
Configure appropriate TTLs, implement cache invalidation, and monitor cache performance.