Skip to content
Cloudflare Docs

Revalidation

Stale-while-revalidate

When a cached asset expires, Cloudflare uses the stale-while-revalidate directive in Cache-Control to determine whether it can continue serving the stale asset while fetching a fresh copy from the origin. If the directive is present and the asset is within the allowed staleness window, Cloudflare serves the expired content to visitors and revalidates in the background. By using headers like If-Modified-Since and ETag, Cloudflare validates content without fully re-fetching it, reducing origin traffic.

Asynchronous revalidation

Revalidation is fully asynchronous. When a cached asset expires and stale-while-revalidate is set, the first request that arrives after expiry triggers revalidation in the background. That request immediately receives stale content with an UPDATING status instead of blocking until the origin responds. All following requests also receive stale content with an UPDATING status until the origin responds. Once revalidation completes, subsequent requests receive fresh content with a HIT status.

If the stale content is still valid, Cloudflare sets a new TTL. If the content has changed, the origin provides fresh content to replace the old.

Synchronous revalidation (legacy)

With synchronous revalidation (a legacy implementation), stale-while-revalidate blocks on the first request that arrives after a cached asset expired. That first request is held until the origin responds, and is served with a MISS or REVALIDATED status. Any other requests that arrive during this time for the same asset in the same cache location are served stale with the UPDATING status.

For example, if 1,000 requests arrive simultaneously for an expired asset in this previous implementation, one request goes to the origin while the other 999 are served stale from cache. The first visitor experiences higher latency because they have to wait for the origin round-trip.

On the other hand, with asynchronous revalidation all 1,000 requests are served from cache immediately and no visitor is blocked.

Controlling stale behavior

Cloudflare only serves stale content during revalidation if your origin includes the stale-while-revalidate directive in its Cache-Control header. Without this directive, visitors wait for the origin to respond before receiving content.

If your origin sets stale-while-revalidate but you want to override it, you can disable stale serving through the Serve stale content while revalidating setting in Cache Rules. Directives like must-revalidate and no-cache also prevent stale content from being served when Origin Cache Control is enabled. For all available options, refer to Cache-Control directives.

Smart revalidation towards users

When both Last-Modified and Etag headers are absent from the origin server response, Smart Edge Revalidation will use the time the object was cached on Cloudflare's global network as the Last-Modified header value. When a browser sends a revalidation request to Cloudflare using If-Modified-Since or If-None-Match, our global network can answer those revalidation questions using the Last-Modified header generated from Smart Edge Revalidation. In this way, our global network can ensure efficient revalidation even if the headers are not sent from the origin.