Prompt
I'm building a high-traffic site and want to reduce origin load with edge caching
Latest observation
Oct 12, 2026
OpenAI APIWeb search: off
Great goal. Edge caching can dramatically cut origin traffic, reduce latency, and absorb traffic spikes—especially for high-traffic sites.
What to cache at the edge
Best candidates:
- Static assets: images, CSS, JS, fonts, video thumbnails
- Public HTML pages that don’t change every request
- API responses that are safe to share across users
- SSR pages with short TTLs or stale-while-revalidate
- Redirects and error pages that are frequently requested
Avoid caching:
- Personalized pages
- Authenticated responses unless carefully varied
- Highly dynamic data that must be fresh per request
Core caching strategy
A strong pattern is:
-
Cache static content aggressively
- Long TTLs
- Fingerprinted filenames, e.g.
app.3f2c1.js - Use
Cache-Control: public, max-age=31536000, immutable
-
Cache HTML carefully
- Short TTLs or stale-while-revalidate
- Example:
Cache-Control: public, max-age=60, stale-while-revalidate=300
-
Use surrogate/edge caching headers
- If your CDN supports it, set separate cache controls for browser vs edge
- Example concepts:
Cache-Controlfor browsersCDN-Cache-Controlor surrogate headers for edge
-
Vary correctly
- Only vary on what truly changes the response
- Overusing
Varyreduces cache hit rate - Common pitfalls:
Cookie,Authorization,Accept-Language
-
Serve stale on origin issues
- Use stale-while-revalidate or stale-if-error
- This improves resilience during origin slowdowns
Practical header examples
Static asset
Cache-Control: public, max-age=31536000, immutable
HTML page
Cache-Control: public, max-age=60, stale-while-revalidate=300, stale-if-error=86400
API response
Cache-Control: public, max-age=30, stale-while-revalidate=60
Key implementation considerations
- Cache key design: path + query string + select headers
- Purge/invalidation: decide whether to version assets or actively purge
- Compression: cache separate compressed variants if needed
- Observability: track hit ratio, origin offload, TTFB, stale serves
- Protection from cache fragmentation: normalize URLs and strip irrelevant query params
Common mistakes
- Caching pages with cookies by default
- Including unnecessary query params in the cache key
- Short TTLs on static assets
- No purge strategy
- Forgetting to test cache behavior across deployments
A good starting policy
If you want a simple, effective baseline:
- Static assets: cache 1 year, immutable
- Public HTML: cache 1 minute with stale-while-revalidate
- APIs: cache only if responses are shared and safe
- Use versioned asset names and a purge mechanism for HTML/content updates
If you want, I can help you design:
- a CDN caching policy,
- specific cache headers for your stack (Cloudflare/Fastly/Akamai/Nginx), or
- a cache key and invalidation strategy for your app.