Cloudflare single-URL purge leaves stale copies when the response has Vary: Origin
- Field note
The file came from R2 behind Cloudflare, and the R2 CORS response carried Vary: Origin. Cloudflare then stores a separate copy for each Origin and Accept-Encoding combination it has seen. A single-URL purge removes only the copy for a request without those headers. A bare curl hits exactly that copy, which is why it looks fixed when it is not.
Purging with headers
The purge API accepts headers per file:
{ "files": [ { "url": "https://assets.example.com/model.glb",
"headers": { "Origin": "https://app.example.com",
"Accept-Encoding": "gzip, deflate, br, zstd" } } ] }That works, but it does not close the gap: the client chooses Origin, so anyone can create a variant you will never think to purge. For deleted content that matters, because the copy can be served until max-age runs out.
Removing the variant
- A request transform rule that deletes the
originheader on the asset host (Cloudflare allows it). - A response header rule that sets
Access-Control-Allow-Origin: *, which R2 was already returning.
After that, one URL purge cleared everything. Measured: the first request with an Origin header was a MISS, the next one without headers a HIT.
Two related traps
- Query strings are part of the default cache key, so
/pageand/page?x=1are separate copies. Hostname purge, available on Free since April 2025, clears both. - Purge does not reach browsers. If a broken file was served as
immutablewith a long max-age, browsers keep it, and the only real fix is a new URL.