I'm wondering if it makes sense to compress responses from my server when I'm already using Cloudflare, which also handles compression. Will compressing responses reduce the payload size between my origin server and Cloudflare enough to justify the extra processing overhead?
5 Answers
It really depends on your traffic costs. Reducing the bytes that Cloudflare requests from your origin could save you on infrastructure costs, making compression worthwhile if you're dealing with large amounts of traffic.
Generally, compressing data before it reaches Cloudflare may not provide much benefit since running the same compression algorithm twice on the same file yields minimal improvements. You might actually lose more with the additional computational overhead. It’s worth testing on your own to see if you notice any difference, but odds are you won’t gain much from it.
In most cases, the cost of data transfer is higher than the processing needed for compression, so there can still be a significant benefit to compress if you're transferring large amounts of data.
If you’re serving brotli compressed responses from your origin, and you don’t enable Cloudflare settings that require examining the payload, it can pass through your compressed responses directly, which is faster. Pre-compressing your assets is generally a smart move, even if you don’t configure passthrough.
As far as I know, Cloudflare does compress payloads by default. You can check this in the Network DevTools section by looking at the headers of the response to see if it’s already being compressed.
Related Questions
Cloudflare Origin SSL Certificate Setup Guide
How To Effectively Monetize A Site With Ads