We’re wanting to cache all the html content from a php generated page. And we want to serve the cached version of the page no matter what the query strings are applied.
What steps have you taken to resolve the issue?
So we want example.com and example.com ?fbclid=123 to serve the same cached version of the page. I realise there is a setting in the cache rules section, but it is only for enterprise customers. Is there some way to do this without enterprise level account?
Thank you very much for your suggestions! I did look at the cache settings but it appears it only works for static files like css/js? Caching levels · Cloudflare Cache (CDN) docs
I haven’t tested it but I assume that means it won’t work for cached html?
A redirect won’t work because we still need the query strings, we just don’t want to have to go back to the server for the html for each different query string value, because this means the cache is bypassed for all users with a different click id string.
We also looked at the worker option but we couldn’t work out how to make it work. We put the html content of the page into the worker, but the route setting in the worker doesn’t allow query strings.
Is there some way we can deploy a worker to just catch a single path with specific query strings and call the cached html resource instead of going back to the server?
Thanks very much for this, but am I right that this will just remove the query strings altogether? We’re needing the querystrings but just don’t want to have to go back to the server for each request with a different querystring.
Could you re-write your Worker so it’ll match URLs which contain query?
So you could bound to Worker Route such as example.com/something/* if that should catch and check all the URLs after something/ with a query parameter.
I have to say, using Worker might be costly in such case since we cannot bound a Worker Route to Query parameter, so it’ll be like checking each URL from each search engine trying to visit, crawl, index, bot, attack … might not be great case.
Or just for the style.css?
May I ask if you’re using Free or paid plan type?
So in an example, you’d want to return style.css which is cached, instead of style.css?param=value which would always go to the origin for style.css right?
We are using a paid plan.
Yes your example is correct. We want to return the cached version of example .com instead of going to the origin for example .com?param=value.
You could definitely do this as a worker as we had something similar working.
Basis is to explode the list of querystring parameters, strip out the ones you don’t want and then create a new request to the origin using just the ones you do want and return that to the requester.
Because workers sits in front of the cache the request will load from cache without touching the origin.
You do incur the cost of 1 worker execution per page load for anything on the path in question but that may still be way less than the computation cost of generating at the origin.
Thanks for the suggestion of Snippets @fritex and @Laudian. I have tried using snippets and they work beautifully! From our php we output a static html file for the page and using the snippet we check if a specific querystring exists on a specific uri path, and if it does the snippet runs and instead of going back to the origin, it loads the cached static file instead. There are no limits/cost on how many times a snippet can run.