Back to Blog
team@tinypod.app

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.

cdnperformancecloudflare

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

  • Images (logos, photos, icons)
  • CSS and JavaScript files
  • Fonts
  • Static HTML pages
  • PDFs and downloads

  • Never Cache

  • Authentication responses
  • User-specific data
  • Admin panels
  • API responses with user data
  • Dynamic pricing or inventory

  • 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:

  • Static assets: Cache-Control: public, max-age=31536000 (1 year)
  • HTML pages: Cache-Control: public, max-age=3600 (1 hour)
  • API responses: Cache-Control: no-store

  • Page Rules

    Use Cloudflare page rules for fine-grained control:

  • *.example.com/static/* → Cache Everything
  • example.com/api/* → Bypass Cache
  • example.com/admin/* → Bypass Cache

  • Performance Gains


    Typical improvements with CDN:

  • Static asset load time: 60-80% faster for distant users
  • Origin server load: 50-70% reduction
  • Bandwidth costs: 30-60% reduction

  • 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:

  • DDoS protection
  • SSL/TLS termination
  • Web Application Firewall (basic)
  • Bot management
  • Analytics

  • Every self-hosted app should sit behind Cloudflare. The free tier provides significant performance and security benefits.

    CDN Integration for Self-Hosted Apps | TinyPod | TinyPod