If you have social traffic, paid promotion or using UTM to track your campaign on a website that uses Cloudflare Cache Everything to speed up the site then this article is helpful for you. Social media platform like Facebook adds
fbclid string to your site URL.
Every click that comes from Facebook, adds a unique query string at the end of the URL, which makes every URL unique for every click. Cloudflare treats this click as a new URL and ignores caching. But here is a solution that fixes
Cf-Cache-Status: miss issue due to the fbclid string.
What are Query Strings and how are they helpful
Facebook, Google, Google Analytics, and Google Ads add additional strings at the end of any URL that comes from their platform. This Query string helps to track the traffic source and behaviour of visitors to a website. These strings are very helpful for marketing and monitoring website performance.
When you see “fbclid” in a query string in a URL, it indicates that the visitor came to the website from Facebook.
If you see utm_source, utm_medium and utm_campaign, this means these are Urchin Tracking Module (UTM) that helps to track various marketing channels, campaigns, and mediums. It provides detailed information about the source, medium, campaign, keyword, and content associated with the visit which marketing people use most.
If you have a slow website and want to speed up, then you must check these 11 Proven Ways to Speed Up WordPress Website
Why Cloudflare Cache Miss with Query Strings
Every Query string added to the URL is unique, and therefore Cloudflare treats it as a different page. So, Cloudflare shows
Cf-Cache-Status: miss for these pages. Cloudflare APO already show a cached version to these all strings but if you use Cloudflare Cache Everything then there is a high chance that it shows an uncached version to your user.
One of the users asked a similar question in WP Speed Matters Facebook group –
You can easily solve this problem by selecting “Ignore Query Strings” in the Caching Level. You can find this option in Caching > Configuration in the Cloudflare dashboard. But I do not recommend you use this option. Because it causes problems with dynamic content.
If you have a WooCommerce website then you do not use this option. “Standard” is recommended.
How to Solve Cache Miss for Query Strings in Cloudflare Cache Everything
- Go to Rules > Transform Rules in the Cloudflare Dashboard
- Create a rule and give it the name “Ignore Query Strings”
- Click on Edit expression and add the below Expression code
- Choose Preserve in Path Section and rewrite with statics in Query section (keep blank after ?)
- Click on Deploy
(http.request.uri.query contains "msclkid") or (http.request.uri.query contains "fbclid") or (http.request.uri.query contains "utm_") or (http.request.uri.query contains "ref") or (http.request.uri.query contains "gclid") or (http.request.uri.query contains "fb_") or (http.request.uri.query contains "_ga") or (http.request.uri.query contains "campaignid") or (http.request.uri.query contains "adgroupid")
In the above expression code, we are implementing a rewrite rule that bypasses the query strings when msclkid, fbclid, utm_, ref, gclid, fb_, _ga, campaigned and adgroupid are found in its URL. The cache miss problem will solve but the URL will be the same as before.
The major benefit of it is a performance boost. By default Cloudflare act like a new URL when these strings are found in the URL, so it always delivers an uncached version which doesn’t provides caching benefits. After implementation, now Cloudflare ignores these strings and delivers a cache version.