DevTools Logo

Cache-Control Builder

Cache-Control Builder & Freshness Simulator

Compose Cache-Control directives and see whether browser and CDN caches serve fresh, stale or origin responses over time.

Runs in your browser
Try an example

Directives

4 set
Response directives
Delta-seconds
Companion headers
Response timing
Request context (simulator only — never emitted as a response header)
Paste an existing Cache-Control header

Useful for incident debugging: paste a header from curl -I to load its directives into the builder. Request-only directives such as max-stale go to the request context.

Headers & freshness timeline

3 headers · t=30 min

Response headers

Cache-Control: public, max-age=60, s-maxage=60, stale-while-revalidate=3600
Age: 0
Expires: Thu, 01 Jan 2026 00:01:00 GMT

Freshness simulator

Browser · defaultBrowser: Stale — served while revalidating — browser: stale response served, 29 min into a 1 h stale-while-revalidate window. Refresh happens in the background.
CDN · defaultCDN: Stale — served while revalidating — CDN: stale response served, 29 min into a 1 h stale-while-revalidate window. Refresh happens in the background.
freshstale servedrevalidatedorigin

Details

Choose response directives, or paste a Cache-Control header from curl -I to deconstruct it. The tool emits a canonical header plus Expires, Age and Vary suggestions, then simulates each request time in two lanes: a private browser cache and a shared CDN cache. Change the time slider to see whether a request is fresh, stale-but-served, revalidated or fetched from the origin. max-stale, min-fresh and request no-cache are request-side controls: they affect the simulation and never appear in the generated response header.

More examples

API with a stale-while-revalidate buffer

Cache-Control: public, max-age=60, s-maxage=60, stale-while-revalidate=3600

At t=30 min: browser and CDN serve stale while revalidating in the background. At t=75 min: both block on a revalidation.

A short fresh lifetime keeps data current, while the stale window absorbs reloads and CDN revalidation spikes without users seeing a delay.

Long CDN cache, short browser cache

Cache-Control: public, max-age=60, s-maxage=86400

At t=30 min: the browser lane revalidates; the CDN lane is still fresh for another 23.5 hours.

s-maxage overrides max-age only for shared caches, which is why the two lanes diverge after the first minute.

Sensitive response

Cache-Control: private, no-store

Every request: origin fetch. Nothing is stored by the browser or a CDN.

no-store wins over any freshness directive and is the safe choice for authenticated or personal data. The builder warns about conflicting directives.

Model: RFC 9111 freshness (max-age/s-maxage → Expires → 0.1 × Last-Modified age), RFC 5861 stale windows and RFC 8246 immutable. A two-layer browser/CDN approximation; real caches can add their own rules.

Examples

Browser fresh, CDN fresh, then stale-served

Input
public, max-age=3600, s-maxage=3600, stale-while-revalidate=1800; t=30 min
Output
browser: fresh (age 30 min, lifetime 60 min)

The age is below max-age, so both lanes serve the cached body without contacting the origin.

Inside and outside the stale window

Input
max-age=3600, stale-while-revalidate=1800; t=75 min / t=90 min
Output
t=75 min: stale served while revalidating; t=90 min: blocking revalidation

The stale window opens at 60 min and closes at 90 min; past it the cache must wait for the origin.

Heuristic freshness

Input
no max-age, no Expires; Date − Last-Modified = 2 hours, LM factor 0.1
Output
freshness lifetime = 12 min

RFC 9111's heuristic estimate is used only when neither explicit lifetime mechanism is present.

About this tool

A Cache-Control header is a small string with a large behavioral footprint. This builder lets you tick response directives such as max-age, s-maxage, no-cache and stale-while-revalidate, then shows the canonical header your server should emit. It also simulates what each cache actually does at a chosen moment, so you can see the reason a response is fresh, stale, revalidated or fetched from the origin.

The simulation has two lanes: a private browser cache and a shared CDN cache. They deliberately disagree when s-maxage, private or Authorization change the rules. A time slider scrubs through requests after the response Date; a sequential mode steps through reloads so a background refresh or 304 resets the stored age, which is how real cache entries evolve.

Everything follows RFC 9111 freshness precedence: max-age (or s-maxage on shared caches), then Expires minus Date, then the heuristic 0.1 × (Date − Last-Modified) when neither is present. RFC 5861 defines the stale windows and RFC 8246 defines immutable. Request-only directives such as max-stale and min-fresh are kept in a separate request context because they are legal on requests but invalid in a response header.

What this tool does not do

  • The two lanes model one browser cache and one shared cache; multi-CDN hierarchies, service workers and browser-specific heuristics are not simulated.
  • Sequential mode assumes one request per minute and a successful background refresh; it does not model network latency or partial responses.
  • stale-while-revalidate and stale-if-error come from the experimental RFC 5861 and are not supported uniformly by every cache.
  • Heuristic freshness uses a fixed LM factor of 0.1; real implementations may clamp or ignore heuristic lifetimes.
  • The tool emits header syntax and predictions only — it does not change any server, CDN or browser configuration.

How to use this tool

  1. Pick directives or paste a header

    Start from a preset such as API fresh or Static asset, tick individual flags, or paste a Cache-Control value from curl -I and click Load header to deconstruct it.

  2. Set response timing

    Enter Date, Last-Modified and optionally Expires, plus the Age header value already accumulated in caches. Leave Expires empty to use max-age or the heuristic.

  3. Compose the header

    Read the canonical Cache-Control value and its companion Expires, Age and Vary suggestions. Copy the whole bundle or just the directive string.

  4. Scrub the timeline

    Move the time slider to any minute after the response. Browser and CDN lanes report fresh, stale-served, revalidated or origin with the age and lifetime used for the decision.

  5. Model the request and variants

    Toggle Authorization, request no-cache or origin failure, enter max-stale/min-fresh, and add Vary headers with simulated values to see per-key cache entries.

Use cases

Set CDN headers for a new API

Compare max-age and s-maxage in two lanes before shipping, and verify that a short browser lifetime does not undermine CDN offload.

Debug a stale-data incident

Paste the header from curl -I, set the request time to when users saw old data, and read which lane allowed a stale response and why.

Tune stale-while-revalidate

Watch the stale window open and close on the timeline, then switch on sequential reloads to see how a background refresh changes later requests.

Protect authenticated content

Compare private, no-store and Authorization scenarios to confirm shared caches cannot keep a sensitive response.

Directive vocabulary

DirectiveApplies to
max-age=ΔBrowser and shared caches
s-maxage=ΔShared caches only
no-cacheAll caches
no-storeAll caches
stale-while-revalidate=ΔRFC 5861
stale-if-error=ΔRFC 5861
private / publicShared caches
Vary: valuesAll caches

Delta-seconds are always integers ≥ 0. Negative or fractional values are rejected by the builder's validation.

Common mistakes

Mistake:Putting max-stale or min-fresh in a response header.

Fix:They are request directives. Use the request context controls; the response serializer never emits them.

Mistake:Expecting stale-while-revalidate to extend freshness.

Fix:It only applies after max-age expires. A response without an explicit lifetime is stale immediately.

Mistake:Assuming s-maxage shortens browser caching.

Fix:s-maxage affects shared caches only; the browser lane still uses max-age, Expires or the heuristic.

Mistake:Combining no-store with max-age and hoping max-age wins.

Fix:no-store wins: nothing is stored, so no freshness lifetime can apply. Remove conflicting directives.

Mistake:Forgetting Vary: Authorization on personalized responses.

Fix:If a shared cache is allowed to store an authenticated response, Vary on the credential-bearing header or keep the response private.

Frequently asked questions

What's the difference between no-cache and no-store?

no-cache allows a cache to store the response, but it must send a conditional request (If-None-Match or If-Modified-Since) before every reuse. A 304 response lets the cache serve the stored body without downloading it again. no-store forbids storing a copy at all, so every request is a full origin fetch. Use no-cache for content that changes but benefits from validation; use no-store for authenticated or personal data that must not be retained.

How does stale-while-revalidate work?

After max-age expires, a stale-while-revalidate window lets a cache serve the stale body immediately while it refreshes the entry in the background. In the simulator the browser or CDN lane shows 'stale served while revalidating' inside that window and 'revalidated' once it closes. The directive never extends freshness — it only makes the stale period non-blocking. It comes from RFC 5861, so support varies by cache.

Do browsers or CDNs win with s-maxage?

Neither overrides the other across layers. s-maxage replaces max-age and Expires only for shared caches such as a CDN; browsers keep using max-age, then Expires, then heuristic freshness. That is why the two lanes can disagree: with max-age=60 and s-maxage=86400, the browser revalidates after a minute while the CDN stays fresh for a day.

How does the Age header affect freshness?

Age is the number of seconds the response has already spent in caches. The simulator adds it to the age of a newly stored entry, so a response with Age: 120 and max-age=60 is already stale at t=0. After a 304 revalidation or a successful background refresh, the stored age resets to zero — turn on Sequential reloads to see this happen.

What does Vary do to caching?

Vary names request headers that form the cache key. Vary: Accept-Encoding gives separate entries to gzip and br responses, which the tool shows as separate lanes when you list those variants. Vary: * means no request can match the stored entry, so the response is effectively uncacheable and every request goes to the origin.

Why can't I put max-stale in the generated response header?

max-stale, min-fresh and request no-cache are request directives defined in RFC 9111 §5.2.1. A server sending them in a response produces an invalid or ignored Cache-Control value. The builder keeps them in a separate request context that changes the simulated verdicts but is never serialized into the response header.

When does heuristic freshness apply?

Only when a response has neither max-age/s-maxage nor Expires. RFC 9111 allows a cache to estimate freshness from Last-Modified; this tool uses the common LM factor of 0.1, so a document last changed two hours ago gets an estimated lifetime of 12 minutes. Adding Expires or max-age takes precedence over the heuristic.

Does this tool actually test my CDN configuration?

No. It is a client-side model of RFC 9111 freshness decisions for one browser cache and one shared cache. Real CDNs add their own rules, hierarchical caches and edge location behavior, so use the simulator to explain and predict directive semantics, then verify the deployed headers with curl -I and your provider's logs.

References & standards