stale-while-revalidate
stale-while-revalidate (SWR) is a Cache-Control extension (RFC 5861) that lets a cache serve an expired response immediately while it fetches a fresh copy from the origin in the background. The visitor gets cache speed; the next visitor gets fresh content. It removes the worst moment in caching — the synchronous origin wait at expiry.
Syntax
Cache-Control: max-age=600, stale-while-revalidate=120
Fresh for 10 minutes. For 2 minutes after that, the cache may still answer with the stale copy — but must kick off a background revalidation. Past the SWR window, the next request waits for the origin like a normal miss.
Support is the fine print
- Browsers: Chrome and Firefox honor it for HTTP cache entries.
- CDNs: support varies more than most people assume. Fastly and
bunny.net support it; Cloudflare's classic edge cache historically served stale only
while updating in specific cases (
cf-cache-status: UPDATING), and the Workers Cache API ignores SWR entirely — we measured that on a production site. - Related directive:
stale-if-errorserves stale when the origin is down — different trigger, same spirit.
What SWR doesn't fix
SWR only helps when there is a stale copy to serve. A cache that's simply empty — after a purge, a deploy, an eviction, or at an edge location that never saw the URL — has nothing stale to give, and the first visitor takes the full miss penalty (3.5× slower at the median, in our measurement of 408,000 requests). SWR smooths expiry; warming fills the gaps SWR can't reach. They compose well: long s-maxage, a modest SWR window, and scheduled warming for the long tail.