Cache: Ignoring specific Query Strings

I’ve setup page rules to edge cache everything for static pages.

Query Strings do affect HTML responses in my case. My caching level is set to standard.

However, certain query strings that may be appended to URLs from referrers, like ?gclid from Google, don’t affect my HTML response. The following two URLs would have the same response:
example.com/page?view=one
example.com/page?view=one&gclid=v7kacuw3txurt3crut36acx

How can I serve the cached version of the first URL to requests for the second URL?

The gclid is randomized, pretty much all traffic from Google would not see edge cached responses now.

Have you tried using the ignore query string caching level instead?

Actually that might require a custom cache key which is an ENT feature… you could also try using workers.

But will that cache all the other HTML? Or does ignore query string even apply to HTML?

I thought the point to Cache Everything was to scoop up all the HTML urls that regular caching doesn’t get.

I can’t use ignore query string because other query strings do affect responses.

example.com/page?view=one
may yield a different response than
example.com/page?view=two

Open your ears when people in software say ‘you can also try…’ :joy:

Here’s my worker in case anybody needs it in the future:

addEventListener('fetch', event => {
  let url = new URL(event.request.url)

  if (url.searchParams.has('gclid'))
   url.searchParams.delete('gclid')

  event.respondWith(
    fetch(url, event.request)
  )
})
3 Likes

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