Serve from Cloudflare cache for specific parameters?

Has anybody solved this Cloudflare problem?

When you set up a caching for

it will serve from the Cloudflare cache.

but if somebody goes through


it won’t. Only solution I’ve found so far is to get the business package from Cloudflare which starts at 2k/month.

Sales Team never reached out to me 😕

There are a few solutions, and it depends on whether or not you use query parameters at all in your application/website.

If you never use query parameters, set the Caching Level:

If you just want to strip certain query parameters, then use Transform Rules to strip the params you do not want. This can also be used to selectively remove query strings from certain assets (so you can target all .css files to remove all query strings).


I’m using query parameters add-to-cart, for example. I understand how I could use caching levels to achieve what I want, but I’m afraid that only works if you don’t use query parameters on your website. I can’t find that setting under page rules.

Also for example when you run Facebook Ads. They add a parameter fbclid that has a unique query string. That will stop Cloudflare from sending from it’s own cache.

I don’t know if I’m missing something, but assuming that on average costs half a second on a lot of websites, this is a million dollar problem.

I assume this article talks about it directly:

I’m afraid I only need this feature from Cloudflare. I hope they can make me a good price.

What comes to my mind is:

  1. Use a Cloudflare Page Rule to redirect any URLs which contain that kind of part
  2. Use a Cloudflare Workers to try to achieve the same
  3. Use a Cloudflare Transform URL - > Rewrite (in the background it’s working good, while the visitorURL in the Web browser sees the URL with the query strings)

There are few topics about it here, but I’d have to find them first using :search: .

Page Rule for example:

Cloudflare Workers idea:

Transform Rule idea:

Transform Rule example:

Could be I am wrong. @michael pointed good references for it.



Thank you very much for your help. That was very helpful. I’ve not yet tried the transform rule idea, but I did set up a worker and it works as the developer toolbar shows cf-cache-status:HIT, even though I have a fbclid or utm-source attached.

However what I wonder is, will tracking still work the same way. I did try it, since I have first party tracking and even though I respond with the cached response the utm parameters were tracked. But I don’t know why. Shouldn’t they stop working if Cloudflare responds with the cached version?

In general, yes. If your Origin server is not varying its response based on the query parameter, then using the query parameter to shard the cache is just a waste of resources.

In general, these marketing parameters are picked up by client side javascript, and they work so long as the parameter still appears in the URL. If you redirect the request to one without the query parameter, then the client side tracking will not work.


That’s amazing. Then I think I’ve solved the problem. From what I can see on my backend Indeed tracking seems to work.

For future readers I did the Worker solution not the Transform solution. From what @michael said.

Also here a picture showing, that most of the requests are served by Cloudflare now:


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.