Cloudfare doesn't serve brolti content from my server

I’ve recently moved my site to cloudfare and it’s been great, but there is one issue that I can’t really understand

My server compress static resources once at startup with gzip and brotli with best compression level. Results are stored in memory so it’s very efficient to serve
I’ve noticed that cloudfare fetched those resources from my server, but re-compress them with a lower compression level before serving them to users, resulting in bigger file size

I’ve added a ‘no-transform’ directive to Cache-control header, which works fine for gzip, but now cloudfare refuse to serve those resources with brotli, even if the client accept it:

In summary, on localhost:

curl https://localhost:443/style.css -H 'Accept-encoding: gzip' -> serves resource with **gzip**
curl https://localhost:443/style.css -H 'Accept-encoding: br'    -> serves resource with **brotli**

behind cloudfare:

curl -H 'Accept-encoding: gzip' -> serves resource with **gzip**
curl -H 'Accept-encoding: br'    -> serves resource uncompressed

How can i make cloudfare serve brotli content directly from my server ?

You can pass the br requests to use a different cache Key by appending a query parameter using a Transform Rule when the Request has an Accept-Encoding header containing br.

Similarly if you want to do your own gzip. Potentially you will end up with three different objects in the Cache for each URL, one for both compression types, and another for uncompressed content.

1 Like

Just had a read on

If you’re already using gzip we will honor your gzip settings as long as you’re passing the details in a header from your web server for the files.

Cloudflare only supports the content types gzip towards your origin server and can also only deliver content either gzip compressed , brotli compressed , or not compressed .

So gzip should be possible with your origin, if your header is set correct. For br you can try @michael’s workaround.

1 Like

thanks for the answers, I’ll try that

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