Stale-if-error is a Cache-Control extension directive that allows a cache to serve an expired (stale) response when an attempt to fetch a fresh copy from the origin fails. In content delivery, it turns a cached object into a safety net during origin outages, so users keep receiving content instead of an error page.
The directive is defined in RFC 5861 together with its sibling stale-while-revalidate. It takes a value in seconds, for example Cache-Control: max-age=600, stale-if-error=86400, which means the response is fresh for ten minutes and may still be served for up to one day after expiry if the origin is unavailable.
How stale-if-error works in a cache
Stale-if-error activates only when a cached response is past its freshness lifetime and the cache tries to revalidate or refetch it. If that request ends in an error condition, the cache may return the stale copy instead of passing the failure to the client.
RFC 5861 defines an error as a 500, 502, 503 or 504 status code, or a situation in which the origin cannot be reached at all, such as a connection refusal or timeout. A 404 or other 4xx response is not treated as an error for this purpose, because it is a valid answer from a working origin.
The window is measured from the moment of expiry, not from the time the response was stored. The table shows how a cache handles a request at different points in the lifetime of an object sent with max-age=600, stale-if-error=3600.
| Age of cached copy | Origin state | Cache action |
|---|---|---|
| 0 to 600 s | Any | Serve fresh copy without contacting origin |
| 600 to 4,200 s | Healthy | Fetch or revalidate, serve new response |
| 600 to 4,200 s | 5xx or unreachable | Serve stale copy instead of the error |
| Over 4,200 s | 5xx or unreachable | Pass the error to the client |
Where the directive can be set
Stale-if-error can appear in both response and request headers, and the two placements mean different things. In a response, the origin grants permission to caches; in a request, a client states how much staleness it is willing to accept during failures.
| Placement | Who sets it | Effect |
|---|---|---|
| Response Cache-Control | Origin server | Allows shared and private caches to fall back |
| Request Cache-Control | Client or upstream proxy | States the acceptable stale age on error |
| Surrogate-Control or CDN header | Origin for edge only | Applies the fallback at the CDN, not in browsers |
| CDN configuration rule | Operator | Overrides or adds the behavior per path |
Support varies. Major CDNs honor stale-if-error or provide an equivalent setting, often under names such as serve stale or stale on error. Browser support is limited, so the directive mainly protects users through shared caches at the edge rather than in their own browser cache.
Stale-if-error compared with related directives
Stale-if-error belongs to a group of freshness and revalidation controls, and each one answers a different question about when old content is acceptable. Confusing them is a common source of unexpected caching behavior.
| Directive | Purpose | Triggers when | Serves stale content |
|---|---|---|---|
| max-age | Sets freshness lifetime | Always applied | No, defines fresh period |
| stale-while-revalidate | Hides revalidation latency | Copy is stale, origin healthy | Yes, while refetching in background |
| stale-if-error | Masks origin failures | Refetch returns an error | Yes, until the window ends |
| must-revalidate | Forbids stale use | Copy is stale | No, error is returned instead |
| no-store | Prevents caching | Always applied | No, nothing is cached |
The two RFC 5861 directives are complementary rather than alternatives. A typical configuration uses a short stale-while-revalidate window of seconds or minutes for speed and a long stale-if-error window of hours or days for resilience. Note that must-revalidate and proxy-revalidate explicitly prohibit serving stale content, so they should not be combined with stale-if-error on the same response.
Choosing a stale-if-error window
The right window depends on how harmful outdated content is compared with an error page. The decision table below gives typical starting points for common content types.
| Content type | Suggested window | Reason |
|---|---|---|
| Static assets with versioned names | Several days or more | Content never changes under the same URL |
| Article and marketing pages | Several hours to a day | Slightly old text is better than an outage |
| Product listings and prices | Minutes to an hour | Stale prices may cause disputes |
| API responses for dashboards | Minutes | Data should signal age to users |
| Personalized or account pages | Not used | Usually private and not cached at the edge |
Longer windows only help if the object is still in the cache. Edge caches evict rarely requested objects, so low-traffic URLs may be gone when the outage begins. Origin shielding and tiered caching increase the chance that a stale copy survives.
Limitations and risks
Stale-if-error improves availability, but it does not make the origin redundant and can hide real problems. Teams should understand its limits before relying on it.
- Silent outages: users see working pages, so monitoring must watch origin errors directly rather than edge success rates.
- Outdated critical information: security notices, prices or stock levels can remain wrong for the whole window.
- Cache purge interaction: purging an object during an outage removes the fallback copy and exposes the error.
- Uneven support: some caches ignore the directive or apply only part of the RFC 5861 rules.
- Non-cacheable responses: content marked private or no-store never benefits from the fallback.
Used deliberately, stale-if-error is one of the cheapest resilience measures available to a site, because it needs only a header and a supporting cache.
Put simply
Stale-if-error is a permission to show yesterday’s copy when today’s copy cannot be fetched. Imagine a newsstand that normally gets fresh papers every morning. If the delivery truck breaks down, the seller can keep offering the previous edition for a while instead of leaving the shelves empty.
Visitors may see slightly old information, but they still get something useful. The key trade-off is freshness versus availability, and the website owner decides how old is still acceptable.
In practice
A regional news publisher serves its site through a CDN and sends article pages with Cache-Control: public, max-age=120, stale-while-revalidate=60, stale-if-error=43200. Pages are refreshed every two minutes under normal conditions, and the edge may fall back to cached versions for up to 12 hours if the content management system fails.
During a major storm, traffic spikes while a database upgrade goes wrong, and the origin returns 503 errors for 40 minutes. The CDN keeps serving the most recent cached copy of every popular article and the home page. Readers notice only that new stories stop appearing, while the operations team sees the origin alerts and restores the database. No visitor receives an error page on cached URLs, and fresh content resumes as soon as the origin recovers.