Set browser and CDN freshness with Cache-Control
Admin ·
An origin can set one freshness lifetime for a private browser cache and another for a shared cache such as a CDN. Use max-age for the general lifetime and s-maxage to override it for shared caches that can store the response.
Set two response freshness lifetimes
Choose Load example, then Build header. The output is Cache-Control: public, max-age=60, s-maxage=300. A private cache uses the 60-second explicit freshness lifetime. A shared cache uses 300 seconds.
To try a stale window, clear s-maxage and enter 30 under stale-while-revalidate. Supporting caches can then serve eligible stale responses for up to 30 seconds while revalidating. With s-maxage present, shared caches must validate before reusing a stale response.
RFC 9111, Cache-Control response directivesRFC 5861, Cache-Control extensions for stale content
Choose storage and revalidation independently
Select private for a response intended for private caches. Select no-cache to require validation before reuse. Select no-store if the response should not be stored by a cache.
For a versioned asset, immutable indicates that the fresh response can usually be reused without a revalidation request. Set the applicable freshness lifetime separately.
| Setting | Meaning |
|---|---|
| private | Restrict response storage to private caches |
| no-cache | Validate the stored response before reuse |
| no-store | Direct caches to avoid storing the response |
| max-age=0 | Set the explicit freshness lifetime to zero seconds |
RFC 9111, Cache-Control response directivesRFC 8246, HTTP immutable responses
Build and verify a request header
Switch Header direction to Request. Enter 10 under max-stale and select only-if-cached. Build the header to produce Cache-Control: only-if-cached, max-stale=10. A supporting cache can use an otherwise eligible response that has been stale for up to 10 seconds.
To express an unbounded staleness preference, check Allow any staleness with bare max-stale. Empty durations are omitted. For a generated response header, paste the output into the Cache-Control Header Analyzer to verify the declared lifetimes and storage directives.
RFC 9111, Cache-Control request directivesRFC 9111, Cache-Control response directives
Common questions
Which duration should I use for the browser?
Use max-age for the general response lifetime. s-maxage applies to shared caches.
Can I set a private response with s-maxage?
The line can contain both directives. private restricts storage to private caches, while s-maxage only governs shared caches.
Can I enter a fractional second?
Cache-Control delta-seconds are whole numbers. Choose the appropriate integer lifetime, or leave the field empty to omit the directive.
Sources
Put it into practice.
- Cache-Control Header Builder
- Cache-Control Header Analyzer
- HTTP Header Checker
- HTTP Header Diff Checker