Skip to main content
sitewarm
HTTP caching headers

What is stale-if-error?

stale-if-error lets a cache serve a stale response for a set number of seconds when the origin errors or cannot be reached.

stale-if-error is a `Cache-Control` extension, defined in RFC 5861, that lets a cache use a stale response for up to the given number of seconds when revalidation hits an error. RFC 5861 counts as an error any situation that would return a 500, 502, 503 or 504 status. The visitor gets the old page instead of an error page.

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

It works as a response directive and as a request directive. It does not change freshness: a stale response served this way is still stale and should be visibly so, with a non-zero `Age` header.

  • Like `stale-while-revalidate`, it needs a stored copy. An object removed by a hard purge cannot be served stale.
  • `must-revalidate` overrides it: RFC 9111 requires a cache to return an error (which it says should be a 504) rather than reuse a stale response under that directive.
  • Cloudflare reports a stale response served because the origin could not be reached as STALE.

References

  1. RFC 5861: HTTP Cache-Control Extensions for Stale Contenthttps://www.rfc-editor.org/rfc/rfc5861
  2. Fastly: Serving stale contenthttps://www.fastly.com/documentation/guides/concepts/cache/stale/
  3. Cloudflare: Cache responseshttps://developers.cloudflare.com/cache/concepts/cache-responses/

Warm your cache after every deploy

sitewarm requests the pages in your sitemap after a deploy and reports the cache state the CDN returns for each one, with the vantage point it was measured from.