Compression reduces the bytes transferred for HTML, CSS, and JavaScript. The server must choose an encoding the client accepts and label the response correctly. Read the request's Accept-Encoding header rather than assuming every crawler supports Brotli.
Support can differ between crawlers and change over time. Keep gzip available for clients that accept gzip but not Brotli, and measure representative pages before choosing a compression level.
Decide where compression should happen
Your application, web server, or CDN may already compress responses. Check the public response and configuration before adding another implementation.
For a Go service behind Nginx and a CDN, compressing at the web server or CDN can avoid custom middleware that must correctly handle streaming, ranges, optional http.ResponseWriter interfaces, and bodyless responses.
For Nginx with a Brotli module, this is an example for text content:
brotli on;
brotli_comp_level 6;
brotli_types text/html text/css application/javascript
application/json image/svg+xml
application/xml+rss;
For Apache with mod_brotli:
AddOutputFilterByType BROTLI_COMPRESS text/html text/css
AddOutputFilterByType BROTLI_COMPRESS application/javascript
AddOutputFilterByType BROTLI_COMPRESS application/json
Confirm the module and directives are available in your deployed version. Keep a gzip fallback and check whether the CDN transforms the response again.
Request each encoding explicitly
Compare the public response for Brotli, gzip, and no compression:
curl -sS -D - -o /dev/null -H 'Accept-Encoding: br' https://example.com/page
curl -sS -D - -o /dev/null -H 'Accept-Encoding: gzip' https://example.com/page
curl -sS -D - -o /dev/null -H 'Accept-Encoding: identity' https://example.com/page
curl --compressed decodes the response automatically. Use response headers to check negotiation, and save the raw transfer when comparing encoded bytes.
Test HTML and assets, plus HEAD, 204, 304, range, and error responses. Check that:
Content-Encodingis acceptable to the request;- requests for
identitywork unless intentionally refused; Vary: Accept-Encodingis present when caches store multiple representations;Content-Length, when present, matches the encoded body;- compressed images or fonts are not needlessly recompressed;
- conditional requests, ranges, and streaming still work;
- a cached Brotli response never reaches a client that only accepts gzip.
The HTTP compression overview explains the relationship between negotiation and caching. An encoding parser also needs to honor quality values: br;q=0 does not permit Brotli.
Check for duplicate compression
Compare headers and bytes at the application, origin server, and CDN. If one component encodes the body and another strips Content-Encoding without decoding it, the resulting response is broken.
Do not infer PHP compression settings from SERVER_SOFTWARE alone. That value does not describe every proxy in front of the application.
Measure size and cost
Compare transferred bytes, CPU use, response time, cache hits, and decoding errors before and after the change. Check ordinary browser traffic and the accepted encodings recorded in verified crawler requests.
Keep the change if responses are smaller and correctly served at an acceptable CPU cost. Compression can improve serving efficiency, but it does not guarantee more crawling or indexing.
