CodePark/ questions / HTTP caching & CDNs
START PRACTICINGPRACTICE
Frontend question · Browser & web performance › HTTP caching & CDNs

A response was cached with this header. A user requests it again 120 seconds later. What happens?

Cache-Control: max-age=60, stale-while-revalidate=300
The cache serves the stale copy immediately and revalidates in the background

The cache serves the stale copy straight away and revalidates in the background. The response is fresh for 60 seconds. After that, it may be served stale for another 300 seconds while the cache revalidates in the background. At 120 seconds, the request is inside that window.

"The cache waits for the server" is the tempting wrong answer. That only happens after 360 seconds (60 + 300), when the stale window has ended. "Never revalidates" is wrong, because the stale copy triggers a background update. "The request fails" is wrong, because expired responses are revalidated, not rejected.