Stale-while-revalidate is a Cache-Control directive (RFC 5861) that lets a cache return an expired response instantly while it quietly requests an updated version for later requests. The next visitor then gets the fresh copy.
Why it matters
Normally an expired entry forces the user to wait for a full revalidation or download. With this directive the user never waits for the refresh, so latency stays low while content stays reasonably current. It suits content where being a few seconds or minutes old is acceptable, such as news lists, product catalogs or API data. Browsers and many CDNs support it, though implementations differ in detail.
Example
Cache-Control: max-age=60, stale-while-revalidate=300
For 60 seconds the response is fresh and served normally. From 60 to 360 seconds it is stale but may be served at once while a background request refreshes it. After 360 seconds the cache must wait for a fresh response. A related directive, stale-if-error, allows stale responses when the origin fails.
Common mistakes
- Using it for personalized or sensitive pages.
- Expecting instant accuracy; one user may still see old content.
- Setting a very large window, so changes appear very late.
- Assuming every CDN supports it identically. Test with headers.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.