Cache-Control Headers Deep Dive
What you'll learn: How to precisely control caching behavior at CDN edges and browsers using HTTP Cache-Control directives.
Building on CDN caching fundamentals, Cache-Control headers are your steering wheel for determining where, how long, and under what conditions responses should be cached.
Core Cache-Control Directives
max-age=<seconds> tells browsers and intermediate caches how long to store a response before considering it stale. For example, Cache-Control: max-age=3600 means "this is fresh for one hour."
s-maxage=<seconds> overrides max-age specifically for shared caches like CDN edges—not browsers. Use this when you want edge nodes to cache longer than end users: Cache-Control: max-age=300, s-maxage=86400 caches 5 minutes in browsers, 24 hours at the edge.
no-cache doesn't mean "don't cache"—it means "cache, but revalidate with origin before serving." Think of it as "always ask permission first." The edge keeps the content but checks if it's still valid via ETag or Last-Modified headers.
no-store is the true "never cache this" directive. Use for sensitive data like payment confirmations or personal account pages. Nothing should retain this response.
Edge Behavior Nuances
CDNs respect these directives but may add their own logic. A Cache-Control: private directive explicitly prevents edge caching (browser-only). Conversely, public signals the response is cacheable even if it would normally be private (e.g., authenticated requests).
Combining directives is common: Cache-Control: public, max-age=3600, s-maxage=86400 optimizes both browser and edge behavior for different lifetimes.
Key Takeaway:
Master max-age, s-maxage, no-cache, and no-store to control precisely where and how long content lives—s-maxage optimizes edge retention independently from browser caches, while no-cache revalidates and no-store prohibits storage entirely.