Cache-Control & CDN Header Builder

Visually configure HTTP caching directives, CDN edge offloading, and stale-while-revalidate behaviors.

Presets:
Generated HTTP Header
Cache-Control: public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400
Vary: Accept-Encoding
max-age (Browser TTL):3600 seconds (60 min / 1 hrs)
s-maxage (CDN / Proxy TTL):86400 seconds (24 hrs)
stale-while-revalidate:86400 seconds
stale-if-error (Origin Down):0 seconds
Server Configuration Snippet

Architecture Guide to HTTP Caching & Edge CDNs

Properly configuring HTTP caching headers is one of the highest leverage performance and cost-saving optimizations in cloud architecture. By offloading static assets, API responses, and dynamic SSR pages to Content Delivery Networks (CDNs) like Cloudflare, AWS CloudFront, and Fastly, origin compute load can be reduced by 70% to 95%.

Key Cache-Control Directives Explained

  • max-age vs s-maxage: max-age instructs the end-user's browser how long to store the response locally; s-maxage overrides this exclusively for shared public proxies and CDN edge servers.
  • stale-while-revalidate (RFC 5861): Instructs the CDN/browser to immediately return an expired cached copy to the client (sub-10ms response time) while asynchronously fetching an updated representation from the origin in the background.
  • immutable: Informs browsers that the asset body will never change over time. When used with content-hashed filenames (e.g. bundle.a8f9c2.js), browsers completely bypass revalidation requests during page reloads.
  • no-cache vs no-store: no-cache allows storing the response but forces the browser to validate its freshness via If-None-Match (ETag) before reuse; no-store forbids caching entirely on any disk or memory cache.

The Critical Role of the Vary Header

Whenever an endpoint serves different responses based on request headers (such as compression algorithms with Vary: Accept-Encoding or localized content with Vary: Accept-Language), the Vary header must be explicitly sent to prevent CDNs from serving compressed gzip payloads to clients that cannot decompress them.