Cloudflare workers (fetch) removing content-encoding headers (gzip)

We are using Cloudflare as a CDN to serve our static resources from storage.

All our files are already stored compressed (gzip) and origin is sending content with correct headers (content-encoding gzip). If we hit origin directly with the browser, we get gzipped content (small file).

However, when we use Cloudflare, we get uncompressed files, without content-encoding header and browser downloads a large file.

What do we need to do to make sure CloudFlare does not alter contents or headers?

Is your worker just a fetch or adds other features?

Hello @adaptive

The worker also verifies signed cookies. This is why workers are being used.

But as far as fetch is concerned, it is just a simple fetch.

async function serveAsset(event) {
  const cache = caches.default
  let response = await cache.match(event.request)
  if (!response) {
    response = await fetch(event.request);
    if (response.status === 200) {
      event.waitUntil(cache.put(event.request, response.clone()))
    }
  }
  return response
}
1 Like