Consider the query parameter when an image is cached


just starting and moving here from cloudfront.
In cloudfront, we bypassed the cache by changing the query-parameter. that means the image is cached by the complete url.
It seems, this is different in cloudflare.
Example: I alway get the same image, with header cache-status HIT, no matter if i change the parameter ‘v’ :
curl -i

Pagerule: CacheEverything
CachingLevel: Standard

addEventListener('fetch', event => {

const BUCKET_URL = ''

async function serveAsset(event) {
  const url = new URL(event.request.url)
  response = await fetch(`${BUCKET_URL}${url.pathname}`)
  return response

async function handleRequest(event) {
  if (event.request.method === 'GET') {
    let response = await serveAsset(event)
    if (response.status > 399) {
      response = new Response(response.statusText, { status: response.status })
    return response
  } else {
    return new Response('Method not allowed', { status: 405 })

The worker seems to be not touched, if the image is cached.
Any Ideas how to solve this? We hoped to be able to just switch over easily from cloudfront.

Thanks and regards

This can be solved in Cloudflare’s caching levels. The link to this is

Cloudflare’s CDN caches static content according to these levels:

  • No Query String: Delivers resources from cache when there is no query string. Example URL: >
  • Ignore Query String: Delivers the same resource to everyone independent of the query string. > Example URL:
  • Standard (Default) : Delivers a different resource each time the query string changes. > Example URL:

More information can also be found here How the Cache works · Cloudflare Workers docs

Thank you.
But that’s exactly what doesn’t seem to work in my case. I must have missed something.

I just noticed that I just appended the pathname, not the qeries.

I replaced that by = ''
response = await fetch(url)

Now it is working. Thanks.

1 Like

This topic was automatically closed after 31 days. New replies are no longer allowed.