Choosing Brotli or Gzip at the CDN is only the first step. This guide gives you a repeatable way to estimate transfer-size savings, account for compression CPU cost, verify response headers, and confirm that cache variants and fallbacks work for real requests.
Overview
Brotli and Gzip are lossless compression methods commonly used to reduce the size of text-based HTTP responses. A CDN can compress eligible files at the edge, serve files compressed by your build pipeline, or use a combination of both. The correct choice depends on the asset type, the capabilities of the requesting client, the CDN's configuration, and whether the extra processing occurs during deployment, at the edge, or at the origin.
For most websites, compression is most useful for HTML, CSS, JavaScript, JSON, SVG, XML, and other text-like responses. It is usually less useful to compress already-compressed formats such as JPEG, PNG, WebP, AVIF, MP4, ZIP, and many font formats. Recompressing those files can add CPU work without materially reducing the response size.
Brotli generally offers a useful alternative to Gzip for supported clients, particularly for text assets. Gzip remains important as a fallback because a robust CDN configuration should not assume every client accepts Brotli. Do not judge the result from one synthetic request alone. Compare the encoded response, the cache status, the transfer size, and the behavior of a request that does not advertise Brotli.
| Area | Brotli | Gzip | Operational implication |
|---|---|---|---|
| Browser support | Supported by modern browsers and clients, but verify older or specialized clients in your audience. | Broadly established as a fallback. | Offer Brotli when accepted and retain Gzip or identity fallback where appropriate. |
| Compression levels | Higher levels can improve density while increasing compression time and CPU use. | Levels also trade compression time for density and CPU. | Use faster settings for on-demand edge compression and stronger settings during builds. |
| Suitable assets | HTML, CSS, JavaScript, JSON, SVG, and other text. | The same text-oriented asset classes. | Exclude assets that are already compressed unless testing proves otherwise. |
| CPU cost | Can be higher at more aggressive settings. | Often simpler for broad fallback delivery. | Measure edge or origin CPU, not only bytes saved. |
| Transfer-size savings | May produce a smaller result for the same text asset, depending on content and settings. | Provides meaningful reduction for many text responses. | Calculate savings from your own representative files. |
| Cache variation | Responses may vary according to Accept-Encoding. | Also requires correct negotiation and variant handling. | Check Vary: Accept-Encoding or the CDN's equivalent behavior. |
| Fallback behavior | Should fall back to Gzip or an uncompressed response when unsupported. | Can serve as a fallback or be used directly. | Test Brotli, Gzip, and no advertised encoding. |
How to estimate compression benefits
Use a small sample rather than a single headline file. Select representative HTML documents, CSS bundles, JavaScript bundles, JSON responses, and SVG files. Record each file's uncompressed size, Brotli size, and Gzip size at the settings you intend to deploy.
For each file, calculate the reduction with this formula:
reduction percentage = (original bytes - compressed bytes) / original bytes × 100
To estimate the effect across a page or request mix, use a weighted calculation:
weighted transfer size = sum(request count × compressed response bytes) / sum(request count)
This prevents a small icon or unusually large bundle from distorting the result. If you know the approximate request volume for each asset, also estimate the monthly byte reduction:
monthly bytes saved = requests per month × (baseline bytes - compressed bytes)
These figures estimate transfer reduction, not total page weight. They do not include headers, connection overhead, retransmissions, or the effect of browser caching. Treat them as planning inputs and validate the result with CDN analytics and real-user measurements.
Compression can also affect time to first byte when it is performed on demand. A smaller response may finish downloading sooner, but an expensive compression operation can delay the first byte if the edge or origin must compress before sending. Compare both transfer size and timing. For static assets, precompressing during a build can move that CPU cost away from the request path, provided your CDN can select the correct encoded variant.
Inputs and assumptions
Before changing CDN compression settings, document the inputs that make your estimate meaningful:
- Asset inventory: List text and binary asset types separately. Start with files that are sent frequently or contribute materially to page weight.
- Baseline: Record the current response size and encoding. The baseline may be uncompressed, Gzip, or a build-generated file.
- Compression settings: Note the Brotli and Gzip levels, whether compression occurs at the origin or edge, and whether static precompressed files are used.
- Client mix: Identify which clients request Brotli, Gzip, or no compression. A Brotli-only estimate overstates savings if a significant portion of requests use another representation.
- Cache behavior: Confirm whether the CDN caches encoded variants separately and whether the cache key or response handling respects
Accept-Encoding. - Exclusions: Exclude images, video, archives, and other already-compressed formats unless a controlled test demonstrates a benefit.
- Measurement conditions: Use the same URL, query string, protocol, cache state, and response content when comparing results.
A correct response should also have a suitable Content-Encoding value when compression is used and a matching Content-Type. Do not confuse Transfer-Encoding with content compression. If the response is transformed by a proxy, inspect the final response received by the client as well as the CDN dashboard.
Worked examples
Assume a JavaScript bundle is 300,000 bytes before compression. In a controlled test, the Brotli response is 78,000 bytes and the Gzip response is 92,000 bytes. The estimated reductions are:
- Brotli:
(300,000 - 78,000) / 300,000 × 100 = 74% - Gzip:
(300,000 - 92,000) / 300,000 × 100 ≈ 69.3%
The difference is 14,000 bytes per request for clients receiving Brotli rather than Gzip. If the file receives 100,000 such requests in a period, the estimated additional reduction is 1,400,000,000 bytes before accounting for browser cache reuse, CDN cache hits, headers, and other traffic conditions.
Now test a small JSON response of 8,000 bytes. If Brotli produces 2,600 bytes and Gzip produces 2,900 bytes, Brotli saves only 300 more bytes per response. That may still matter at high volume, but it should be weighed against compression CPU, response latency, and configuration complexity. The correct decision is not always “use the theoretically smallest result”; it is “use the smallest reliable result at an acceptable processing cost.”
Verify with curl
Request Brotli explicitly and inspect the headers:
curl -sS -D - -o /dev/null -H 'Accept-Encoding: br' https://example.com/assets/app.js
Repeat for Gzip:
curl -sS -D - -o /dev/null -H 'Accept-Encoding: gzip' https://example.com/assets/app.js
Test a client that advertises neither encoding:
curl -sS -D - -o /dev/null -H 'Accept-Encoding:' https://example.com/assets/app.js
Look for Content-Encoding, Content-Length or a transfer-size indicator, Vary: Accept-Encoding, cache-status headers, and any CDN-specific age or cache headers. Run each request more than once so you can distinguish an initial miss from a cached response. If the Brotli request receives a Gzip response, check the CDN feature toggle, file type rules, client negotiation, and whether an upstream proxy is rewriting headers.
Deployment verification checklist
- Enable compression only for tested text-based content types.
- Confirm Brotli is offered to clients that advertise
br. - Confirm Gzip or an intentional identity response is available as fallback.
- Verify cache variation by
Accept-Encodingand test for cross-variant delivery. - Check that compressed responses are not being double-compressed.
- Compare response sizes, cache hits, TTFB, and origin or edge CPU before and after deployment.
- Purge affected objects when changing compression behavior, then retest warm-cache requests.
- Check JavaScript, CSS, HTML, JSON, SVG, and error responses separately.
When to recalculate
Revisit your Brotli-versus-Gzip estimate after a CDN migration, origin change, build-pipeline update, compression-level change, protocol change, or substantial change in asset sizes. Recalculate when a framework introduces a new bundle format, when a site begins serving more API traffic, or when cache rules are modified. A new CDN dashboard may also use different names for cache hits, encoded bytes, or compression savings, so map its metrics to the same inputs rather than comparing labels directly.
As a practical routine, keep a small benchmark set under version control and test it after major releases. Include one HTML page, one stylesheet, one script bundle, one JSON response, and one SVG. Record original bytes, Brotli bytes, Gzip bytes, response headers, cache status, and request timing. Review the set at least whenever your performance process calls for a recurring audit, and sooner when production metrics show a change.
For broader testing, combine command-line checks with a repeatable browser performance workflow such as the one described in this CDN performance testing guide. If compressed assets are served through an image or asset optimization layer, review how format and cache variants are handled in the CDN image optimization guide. Finally, use CDN analytics to verify whether smaller responses are translating into healthier cache behavior and useful performance improvements.
The next time you change a CDN setting, do not rely on the dashboard toggle alone. Capture the three curl responses, compare representative files, inspect cache variation, and record both bytes and timing. That short verification cycle turns compression from an assumed optimization into a measurable part of your website speed optimization process.