Cache: Ignoring specific Query Strings

caching

#1

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.


#2

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


#3

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


Cache Everything and Query String
#4

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.


#5

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


#6

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)
  )
})

#7

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