Single URL purge not working, purge everything does work

I would like to use the API to purge individual files. These are .js files containing some JSON data from customers. Should be cached for most of the time but if customer changes some settings i need to purge the cache for that file immediatly.

When i do an exact URL purge it does not work, CF keeps the old version. If i do purge everything it does work. I read that the request headers are part of cache key. Since the .js file is a public file with possible millions of views, i can’t track which headers were used.

Also i think if we do a purge single file, it should purge all cache for that specific url.

How can i simply purge a single url? It should be so simple.

  • I set browser cache bypass (no store)
  • CF edge cache (1 day ttl)
  • I use PHP8.x with curl to call the api

The documentation for this API is a complete mess. There are two contradictory sets of docs, one at Purge cache · Cloudflare Cache (CDN) docs and one at Cloudflare API Documentation and you need to read both, as well as Cache Keys · Cloudflare Cache (CDN) docs , to work out how to use it.

One set of docs says all tier levels can “purge by URL”. The bad news is that, as far as I can tell, these docs are wrong. They actually mean to say you can “purge by cache key”. What you (and I) want, i.e. “purge by URL” is effectively “purge by prefix” and it’s an enterprise-only feature.

So, mere mortals such as us have to use “purge by cache key”. The good news is that the default cache key doesn’t include much that’s likely to be present very often, except the “Origin” header. So if you know what site is fetching your .js files, you know the value for that, and you’ll be able to achieve what you want.

The other fun bit is that the API docs don’t actually tell you what the parameters are for “purge by cache key” - they seem to have forgotten or accidentally deleted that part of the page. But by putting all the different resources I mentioned earlier together we can work out that you want your API request body to look something like this:

    "files": [
            "url": "",
            "headers": {
                "origin": ""

Thank you so much, although i don’t always know the origin since my tag is embedded in customers websites.

I think this used to be a “free” tier feature as i noticed many people saying it didn’t work (anymore) after years. Crazy how something basic as this is considered “Enterprise”.

Thanks again.