MORTIMERDEV GUIDES / HTTP CACHING

s-maxage vs max-age: how long browsers and CDNs cache a response

3 minute read Updated Sources checked 30 November 2026

Short answer: max-age is how many seconds every cache can reuse a response without asking your server. s-maxage replaces it for shared caches (CDNs and proxies) only; browsers ignore it. So Cache-Control: public, max-age=60, s-maxage=3600 means up to one minute in the browser (less any time the copy already spent at the CDN) and one hour at the CDN.

Who uses which

CacheUsesIgnores
The visitor's browsermax-age, then Expiress-maxage
A CDN or proxys-maxage, then max-age, then Expires—

The first one present wins, and Expires is ignored whenever there's a max-age (or, for a CDN, an s-maxage). Neither directive stops anything being stored: max-age=0 still stores the response, it's just stale straight away and has to be checked with your server before reuse.

Why have two

You can purge a CDN when you deploy. You can't purge visitors' browsers. So the usual pattern is to cache longer at the CDN and shorter in browsers:

Cache-Control: public, max-age=0, s-maxage=86400, stale-while-revalidate=60
ETag: "v42"
  • The CDN serves the page for up to a day without touching your server. Vercel then serves the old copy for up to a minute while refreshing it in the background. Cloudflare ignores stale-while-revalidate when s-maxage is set (see below), and CloudFront's docs don't say how it treats the two together, so test it there.
  • Browsers check with the CDN every time. With an ETag, that check is a quick 304 Not Modified.
  • When you deploy, purge the CDN and everyone gets the new page on their next request.

For files whose name changes when their content does (app.3f9c2b.js), cache them for a year everywhere instead:

Cache-Control: public, max-age=31536000, immutable

Time spent in the CDN counts

Freshness is counted from when your server generated the response, not from when the browser got it. A CDN tells the browser how old its copy is in the Age header:

Cache-Control: max-age=60, s-maxage=3600
Age: 50

This copy has been at the CDN for 50 seconds, so the browser can reuse it for only 10 more seconds, not 60. If Age is already more than max-age, the browser treats it as stale straight away. This is why a long s-maxage with a short max-age can make browsers revalidate on almost every request.

Things that catch people out

  • s-maxage also means "revalidate once stale". It implies proxy-revalidate: by the spec, a shared cache mustn't serve the response after s-maxage runs out without checking first. CDNs differ on stale-while-revalidate and stale-if-error alongside it: Vercel honours them, Cloudflare doesn't, and CloudFront supports them but its docs don't cover the s-maxage case.
  • private wins. private, s-maxage=3600 means no shared cache stores it at all, so s-maxage does nothing.
  • Your host may rewrite it. For responses from Vercel Functions where Cache-Control is your only caching header, Vercel uses s-maxage, stale-while-revalidate and stale-if-error itself and removes them before the browser sees the header. Any max-age is kept; with none, the browser gets public, max-age=0, must-revalidate. Static files with headers set in vercel.json are different: Vercel sends their Cache-Control unchanged. We checked both live on this site.
  • Your CDN may cap it. CloudFront keeps the header as it is but caches for no less than the cache policy's minimum TTL and no more than its maximum.
  • There are CDN-only headers. CDN-Cache-Control (RFC 9213) is used by CDNs and ignored by browsers. Vercel and Cloudflare also have their own (Vercel-CDN-Cache-Control, Cloudflare-CDN-Cache-Control) that only they read and don't pass on. These let you set the CDN's lifetime without touching Cache-Control at all.

Check your headers

Paste a response's headers into the HTTP caching explainer, with your CDN chosen, to see how long the browser and the CDN each keep it, what Age does to that, and what your host changes. Its header builder suggests headers for HTML, assets and APIs.