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.

Cached copies of one URL before and after removing the Origin variant Before: with Vary Origin, Cloudflare keeps one copy per Origin and Accept-Encoding. A URL purge removes only the copy for a request without those headers, which curl uses, so browsers keep getting stale copies. After: the Origin header is stripped at the edge, so there is one copy and a URL purge clears it for every client. Before: response has Vary: Origin After: Origin stripped at the edge cache entries for /model.glb no Origin, no Accept-Encoding purged · curl reads this one Origin: app.example.com, br still cached · browsers read this one Origin: app.example.com, gzip still cached Origin: anything a client sends still cached, and you cannot list them One purge request, one copy removed. cache entries for /model.glb one copy (per encoding at most) removed by URL purge The edge drops the Origin header, so it is not part of the cache key. A response rule returns Access-Control-Allow-Origin: *, which R2 was already sending. One purge request, every client fresh.
A URL purge clears one cache entry; Vary: Origin creates many.

Purging with headers

The purge API accepts headers per file:

json
{ "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 origin header 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.

  • Query strings are part of the default cache key, so /page and /page?x=1 are separate copies. Hostname purge, available on Free since April 2025, clears both.
  • Purge does not reach browsers. If a broken file was served as immutable with a long max-age, browsers keep it, and the only real fix is a new URL.