stale-if-error

Caching

Allows caches to serve stale content when the origin returns an error (5xx) or is unreachable. This provides resilience—users see cached content rather than error pages when your origin has problems.

Updated Apr 3, 2026

Full Explanation

stale-if-error is your safety net for origin outages. It tells caches: if the origin returns a 5xx error or is completely unreachable, go ahead and serve the stale cached copy instead of forwarding the error to the user. The value specifies how many seconds beyond max-age the cache is allowed to do this.

The UX difference is huge. Without stale-if-error, an origin outage means your users see 502 or 503 error pages. With it, they see slightly stale content and probably do not even notice anything is wrong. For most content, a page from 5 minutes ago is infinitely better than an error page.

Cache-Control: public, max-age=300, stale-if-error=86400

This header says: keep content fresh for 5 minutes, and if the origin goes down after that, serve the stale version for up to 24 hours. Most CDNs support this natively. In Varnish, the equivalent feature is called "grace mode" and is configured in VCL:

sub vcl_backend_response {
    set beresp.grace = 24h;
}

sub vcl_recv {
    if (!std.healthy(req.backend_hint)) {
        set req.grace = 24h;
    }
}

Examples

A resilient caching header for a content site that should stay up even when origin is down:

Cache-Control: public, max-age=300, stale-if-error=86400

Content is fresh for 5 minutes. If origin fails after that, the cache can serve the stale version for up to 24 hours. Combine this with stale-while-revalidate for the best of both worlds:

Cache-Control: public, max-age=300, stale-while-revalidate=60, stale-if-error=86400

This gives you fast responses during normal operation (stale-while-revalidate) and resilience during outages (stale-if-error).

Frequently Asked Questions

Allows caches to serve stale content when the origin returns an error (5xx) or is unreachable. This provides resilience—users see cached content rather than error pages when your origin has problems.

A resilient caching header for a content site that should stay up even when origin is down:

Cache-Control: public, max-age=300, stale-if-error=86400

Content is fresh for 5 minutes. If origin fails after that, the cache can serve the stale version for up to 24 hours. Combine this with stale-while-revalidate for the best of both worlds:

Cache-Control: public, max-age=300, stale-while-revalidate=60, stale-if-error=86400

This gives you fast responses during normal operation (stale-while-revalidate) and resilience during outages (stale-if-error).