CDN Integration for Self-Hosted Apps
A CDN caches your static assets worldwide. Even self-hosted apps benefit from CDN integration for faster global delivery.
What a CDN Does
A Content Delivery Network caches your content at servers worldwide. When a user in Tokyo requests your site, they get the cached version from a Tokyo server instead of your origin server in Frankfurt.
What to Cache
Always Cache
Never Cache
Cloudflare Setup (Free Tier)
1. Add your domain to Cloudflare
2. Update nameservers at your registrar
3. Enable proxy mode (orange cloud) on DNS records
4. Configure cache rules
Cache Headers
Set proper Cache-Control headers from your app:
Page Rules
Use Cloudflare page rules for fine-grained control:
Performance Gains
Typical improvements with CDN:
Cache Busting
When you deploy new CSS or JS, users might get cached old versions. Solutions:
Filename Hashing
Webpack, Vite, and Next.js automatically add content hashes to filenames: main.a1b2c3.js. New content = new filename = no stale cache.
Cache Tags / Purge
Manually purge specific URLs or tags via Cloudflare API when content changes.
Short TTL for HTML
Cache HTML for 1 hour, not 1 year. HTML references the hashed asset filenames, so fresh HTML loads fresh assets.
Beyond Caching
Cloudflare's free tier also gives you:
Every self-hosted app should sit behind Cloudflare. The free tier provides significant performance and security benefits.