CDN Caching with accept-encoding
Hey, I am trying to understand how encoding interacts with the cache. Currently I have a solution that returns gzip from workers, which is then cached on the CDN and also converted to brotli encoding. I am wondering what happens when a client which only accepts gzip encoding requests a resource that has been cached using brotli. Will this be a new request to the origin to get the same resource with gzip, or will the edge cache convert the brotli cached resource into gzip and return it to the client? Cheers1
2 Replies
It'll convert from cache. Cloudflare doesn't pass the user's accept-encoding to the origin, instead a custom one is used accepting brotli/gzip. There's a nice docs page about it all here: https://developers.cloudflare.com/speed/optimization/content/brotli/content-compression/
Cloudflare’s reverse proxy can also convert between compressed formats and uncompressed formats. Cloudflare can receive content from your origin server with Gzip or Brotli compression and serve it to visitors uncompressed (or vice versa), independently of caching.
Cloudflare Docs
Content compression | Brotli · Cloudflare Speed docs
Cloudflare compresses content in two ways: between Cloudflare and your website visitors and between Cloudflare and your origin server.
I see, I did find that page but it didn't seem clear to me if the cache would do that. It seemed to talk more about requests being converted when coming back from the origin