Hint
Serve the cached (stale) response immediately while fetching fresh in the background — eliminates latency without sacrificing freshness
stale-while-revalidate (SWR) is a Cache-Control extension that says: "serve the cached version immediately (even if stale), but simultaneously fetch a fresh version in the background."
Without SWR: After max-age expires, the next request blocks waiting for the network — the user sees latency on every cache miss.
With SWR:
Cache-Control: max-age=60, stale-while-revalidate=600
# Serve fresh for 60s; serve stale (but refresh) for 10 more minutes
Why good for HTML: HTML pages change infrequently enough that showing a 60-second-old version is fine for most users. Eliminates the "cache miss spike" at deploy time when all users hit the origin simultaneously.
React Query / SWR library: implements the same pattern at the data-fetching layer — show cached data immediately while refetching in the background.