Skip to content

Stale responses

A stale response is a cached object that could be served by the page cache up to 12 hours outside of a resource’s set max-age while the page cache fetches an updated response from the origin to serve for future requests.

For requests to a site’s /wp-json endpoints, a stale response could be served for up to 60 seconds.

The page cache might return a stale response if:

  • An error occurred while establishing a connection with the server when attempting to retrieve a freshened resource.
  • A timeout occurred while establishing a connection with the server, while passing a request to it, or while reading the response header.

Stale responses ensure that intensely trafficked resources on a site continue to be served in a timely fashion. Stale responses can be identified by the X-Cache: STALE HTTP response header.

The stale object (i.e. the previously cached response for a request) can be served immediately by the page cache, and a background request will occur for a freshened resource to update the cache from the origin servers. If another request for the resource is received while the cache is still in the process of updating, the response will be served with a X-Cache: UPDATING HTTP response header.

If the origin server returns a 5xx response, the cached object will continue to be returned until the stale period has ended.

Once the cache is refreshed, any subsequent requests are served the fresh response until the max-age is reached, and the cycle starts again.

The default time to live (TTL) for stale responses can be overridden by setting a custom stale-while-revalidate value for a resource’s cache-control HTTP header.

Last updated: September 11, 2024

Relevant to

  • Node.js
  • WordPress