Purge cache of 1 file which contains many query-string

Hi
I know that there is no way of wildcard cache-purging
but in my case, we have a file named json.js?xx
which xx is a random value. so we have many version of that single file.
is there a way to purge all versions of this file ?

thanks

I am not 100% sure but you might be able to achieve this via Cloudflare’s API.

From what I know about cache purging you can’t purge a wildcard (even though I would love to, or at least by subdomain), you can purge multiple addresses at a time, but every single query string value is different for Cloudflare’s Edge Nodes. I would guess you best bet is purging all (or changing all values for everyone and let the caching headers do their work) and then maybe reworking the way the file is called to prevent this from happening.

I have this same question. Too many possible query-string values to purge individually!

If you can’t script it with the API, your choices are limited:
Enterprise Plan lets you purge by tag. Otherwise, you’ll have to do a Purge Everything.

For static file types such as JavaScript or CSS, for example, you can set a Page Rule with a setting of Cache Level: Ignore Query String, which will make the same file to be served in all requests, regardless of the query string.

So one file would be cached, and all you would need was to purge that one file, though the query string would still be passed on to the browser.

I have tried this on a test website, but for some reason it did not work for a single JS file on the root directory, I don’t know why.

It did work however when I put that file in a folder and created a rule for that folder:

example.com/js/*
Cache Level: Ignore Query String

In case you have a rule with a setting of Cache Level: Cache Everything for all your pages, make sure the page rule to ignore query strings is placed above it, so that it is triggered for the files on that JS folder.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.