Cloudflare revalidates cached content with your origin after the content expires. To revalidate cached content before it expires, invalidate it.
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.
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, your origin answers 304 Not Modified and Cloudflare sets a new TTL. If the content has changed, your origin sends the new content with a new ETag, or a later Last-Modified if it sends no ETag, and it replaces the old content. For the rules your origin must follow, refer to Origin requirements for revalidation.
To revalidate, Cloudflare sends your origin a conditional request. If-None-Match carries the cached ETag, and If-Modified-Since carries the cached Last-Modified. Your origin must follow the HTTP rules for conditional requests:
- Answer a matching
If-None-Matchwith304. On aGETorHEADrequest, if an entity tag listed inIf-None-Matchmatches theETagof the response your origin would send, respond with304 Not Modified, not200(RFC 9110, section 13.1.2 ↗︎). Compare entity tags with the weak comparison function, which ignores theW/prefix (RFC 9110, section 8.8.3.2 ↗︎). - Change the
ETagwhenever the content changes. Responses that share anETagare interchangeable as far as caches are concerned. A strongETagchanges whenever the response body changes, by definition. A weakETagought to change whenever you want caches to stop using old responses (RFC 9110, section 8.8.1 ↗︎). - Keep
Last-Modifiedaccurate. It is the time the content last changed (RFC 9110, section 8.8.2 ↗︎). When aGETorHEADrequest carriesIf-Modified-SincewithoutIf-None-Match, answer304if the content has not changed since that time. When the request carries both, ignoreIf-Modified-Sinceand letIf-None-Matchdecide (RFC 9110, section 13.1.3 ↗︎).
A 200 response that repeats the cached ETag tells every cache that the old and new content are interchangeable, even if its Last-Modified is later, so the new content does not reliably replace the old content. With Tiered Cache, a lower-tier data center revalidates its copy with its upper-tier data center. The upper tier receives the new content from your origin, but its ETag matches the lower tier's copy, so the upper tier answers the lower tier with 304 and the lower tier keeps serving the old content. Browsers that cached the old response revalidate the same way and keep their copy too. This applies whether the content expired or was invalidated.
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.
When Origin Cache Control is enabled, the following Cache-Control directives prevent Cloudflare from serving stale content, per RFC 9111 §4.2.4 ↗︎:
must-revalidate— Prohibits serving stale content; the cache must revalidate with the origin first.proxy-revalidate— Same asmust-revalidate, but only applies to shared caches (like Cloudflare).s-maxage— Impliesproxy-revalidatesemantics, so shared caches cannot serve stale content.no-cache— Requires revalidation before serving any cached response.
If any of these directives are present alongside stale-while-revalidate, Cloudflare will not serve stale content — requests will return EXPIRED instead of UPDATING.
For all available directives or behavior when Origin Cache Control is disabled, refer to Cache-Control directives.
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.