A large JavaScript bundle and a JPEG photograph may arrive from the same distribution. The bundle usually offers useful compression opportunities. Recompressing an already compressed image can add work for little benefit. Set a policy by media type and test it against the actual build.
Choose where compression takes place
Build-time compression suits stable files when the origin can serve the right prebuilt variant. Edge compression suits eligible content arriving uncompressed. Cloud CDN’s Brotli configuration requires Origin Shield and a MIME-type list including text/html. The platform treats Brotli and pulling precompressed content as mutually exclusive modes.
Check negotiation on the wire
Request the same public text file with support for Brotli, gzip, and then an identity representation. Inspect Content-Encoding and verify that each response decodes to the same bytes. Ensure shared caches distinguish the negotiated representation wherever the response varies with Accept-Encoding.
curl -sS -D - -o /dev/null -H 'Accept-Encoding: gzip' https://assets.example.com/app.jsCompare bytes and delivery time
Record transferred bytes for both a large JavaScript bundle and a small stylesheet. Compare cold and warm requests to each. Check that a client offering only gzip still gets a usable response, and record any extra time spent compressing a cache miss before choosing the default.
Sources & further reading
Reader questions
Should the file URL end in .br?
That depends on how you publish it. An HTTP server can negotiate a Brotli representation of the normal asset URL and describe the result with Content-Encoding.
