TapCub is live — analytics, insights and live chat, free on one platform
Analytics

Enable Text Compression: Gzip vs Brotli and What It Saves

How to turn on text compression properly: which files to compress, measured gzip and Brotli sizes, level settings for nginx, Apache and CDNs, and how to confirm Content-Encoding.

Emma Collins Published Dec 3, 2026 14 min read Analytics
Sample data: one HTML page, one stylesheet and two minified JavaScript files, compressed on 2026-12-03. Turning compression on saves far more than the gap between settings.Sample data

Text compression means sending HTML, CSS, JavaScript, JSON and SVG as gzip or Brotli data that the browser unpacks. On our four sample text files it cut transfer from 536,040 bytes to 142,440 with gzip 6 and 121,929 with Brotli 11. Pick the right file types, set levels on purpose and check headers.

What you will learn

  • Compress every text type; WOFF2, PNG and WebP gained 0.3% or less in our test because they are already compressed
  • nginx defaults to gzip level 1 and text/html only; on our files level 1 sent 19.5% more bytes than level 6
  • Precompress static files at Brotli 11; use Brotli 4–5 or gzip 6 for responses built per request

What does "enable text compression" mean?

It means your server is sending HTML, CSS, JavaScript, JSON or SVG at full size when it could send a compressed copy that the browser unpacks on arrival. The browser lists what it can unpack in the Accept-Encoding request header, the server picks one, and it labels the response with a Content-Encoding header. HTTP semantics, RFC 9110 section 8.4, defines that header; gzip is one registered coding and br, the Brotli format of RFC 7932, is another.

The fix lives in server or CDN configuration, not in your application code. That is the point of this guide: compression is a setting you can get fully right in an afternoon, as long as you pick the right file types, set a level on purpose and check the response headers afterwards. A wrong default or a missing MIME type leaves a large share of the benefit unused even when compression looks switched on.

An exchange on a working server looks like this:

DirectionHeaderExample value
RequestAccept-Encodinggzip, deflate, br, zstd
ResponseContent-Encodingbr
ResponseVaryAccept-Encoding

Vary: Accept-Encoding tells shared caches to keep separate copies for clients that accept different codings. Compression shrinks bytes on the wire; it does not reduce the number of requests, which is a separate job covered in make fewer HTTP requests.

Is "Enable text compression" still a Lighthouse audit?

Not as a standalone audit in current versions. Chrome's Lighthouse 13 announcement (10 October 2025) maps the old uses-text-compression audit, together with the redirect and server response time audits, into the Document request latency insight. You will still meet the old wording in older reports, in plugins and in tools that run earlier versions.

The difference matters when you read a green result:

Older "Enable text compression" auditDocument request latency insight
What is checked for compressionText-based responses on the pageThe main HTML document request
Flag rule described in the docsSkips files under 1.4 KiB or with gzip savings under 10%Whether the document response was compressed
EstimateRecompresses with gzipReports the document as compressed or not

The old thresholds come from the audit's documentation; the new scope from the Document request latency insight page. The practical rule: a passing document check says nothing about your stylesheets, scripts or JSON responses, so check those yourself using the steps below.

Which files should you compress?

Compress anything that is text underneath. Skip formats that already contain a compression step. To show the difference, we compressed eight files with gzip level 6 and Brotli quality 11: a built article page, a minified site stylesheet, two minified JavaScript libraries (lodash 4.18.1 and the Vue 3.5.42 global build), a WOFF2 font, a PNG, a WebP image and a flat-colour progressive JPEG used as a social card.

FileOriginal bytesgzip 6Brotli 11Verdict
HTML page96,14219,330 (−79.9%)15,050 (−84.3%)Compress
Stylesheet199,12836,124 (−81.9%)29,509 (−85.2%)Compress
lodash, minified73,23425,871 (−64.7%)23,030 (−68.6%)Compress
Vue build, minified167,53661,115 (−63.5%)54,340 (−67.6%)Compress
WOFF2 font48,25648,249 (−0.0%)48,260 (4 bytes larger)Skip
WebP image41,34441,377 (33 bytes larger)41,348 (4 bytes larger)Skip
PNG image233,299232,690 (−0.3%)232,492 (−0.3%)Skip
Flat-colour JPEG47,16730,257 (−35.9%)29,868 (−36.7%)Fix the image instead

Minified JavaScript still shrinks by about two thirds, so minification does not replace compression. WOFF2 gains nothing because the WOFF 2.0 specification already uses Brotli for the font data. PNG and WebP have their own compression, and running a second pass only spends CPU.

The JPEG is the exception worth understanding. Large areas of one colour leave repeated patterns in the file that a general-purpose compressor can still find. Photographs usually will not behave this way. If gzip cuts a third off one of your images, treat it as a sign the format is wrong for that picture: re-encoding the same card as WebP at quality 80 produced 16,722 bytes, 64.5% smaller than the JPEG and far better than gzipping it. Compare the result by eye, since that re-encode is lossy, and see how to optimize images for web.

Types that belong on the compress list: text/html, text/css, text/plain, text/xml, text/javascript, application/javascript, application/json, application/ld+json, application/xml, application/manifest+json, image/svg+xml and application/wasm.

Gzip vs Brotli: how much do you save?

On the four text files above (536,040 bytes of HTML, CSS and JavaScript), here is the total transfer size and the compression time per setting. Sizes were measured with Node.js 24's built-in zlib and Brotli and matched Python's zlib and the brotli command line tool to within one byte. Times are the sum of the median of 31 runs per file on an Apple M5 Pro laptop; your server will be slower or faster, but the ratios are the useful part.

SettingTotal bytesSavedCompression timeAt 5 Mbit/s
Uncompressed536,0400%none858 ms
gzip 1170,26568.2%about 2 ms272 ms
gzip 6142,44073.4%about 7 ms228 ms
gzip 9141,85873.5%about 9 ms227 ms
Brotli 4144,54773.0%about 3 ms231 ms
Brotli 5134,95974.8%about 5 ms216 ms
Brotli 11121,92977.3%about 380 ms195 ms

The last column is simple arithmetic (bytes × 8 ÷ 5,000,000) and ignores latency and TCP slow start, so read it as an order of magnitude, not a page load time.

Four things follow from the table:

  • Turning compression on at all is most of the win. Even gzip 1 removes 68.2% of the bytes, taking the illustrative transfer from 858 ms to 272 ms.
  • gzip 1 to gzip 6 is worth having. Level 1 sends 27,825 more bytes than level 6 for the same files, which is 19.5% extra.
  • gzip 6 to gzip 9 is nearly nothing. The gain is 582 bytes, 0.4%.
  • Brotli 11 is the smallest but slow. It beats gzip 6 by 20,511 bytes (14.4%) and takes roughly 50 times as long to compress, so it belongs in the build step.
app.tapcub.com

Four text files: bytes sent by setting

total transfer size
Uncompressed536,040 B
gzip level 1170,265 B
gzip level 6142,440 B
Brotli level 5134,959 B
Brotli level 11121,929 B
Sample data
Sample data: one HTML page, one stylesheet and two minified JavaScript files, compressed on 2026-12-03. Turning compression on saves far more than the gap between settings.

Which compression level should you set?

Decide by when the compression happens. web.dev's guide to text compression draws the same line: static files compressed ahead of time can use the most aggressive setting, while responses compressed on request do better with middle settings.

SituationSettingReason
Static CSS, JS and SVG with hashed file namesPrecompress at Brotli 11 and gzip 9 during the buildCPU cost is paid once per deploy
HTML or JSON generated per requestBrotli 4 or 5, gzip about 6 as fallbackA few milliseconds per response, most of the saving
A very busy or CPU-bound serverBrotli 4 or gzip 4 to 6, then measureWatch response time and CPU after the change
Files below about 1 KBLeave uncompressedThey fit in a single packet either way and headers add overhead

Check the defaults before you assume anything. In the nginx gzip module, gzip is off by default, gzip_comp_level defaults to 1, gzip_min_length to 20 bytes, gzip_types to text/html only and gzip_vary is off. In Apache's mod_brotli, BrotliCompressionQuality defaults to 5, and the documentation reserves 11 for cached content.

How do you enable it on nginx, Apache or a CDN?

For nginx, set gzip explicitly, including every text type you serve. text/html is always compressed once gzip is on, so it is not repeated in the list:

gzip on;
gzip_comp_level 6;
gzip_min_length 1024;
gzip_vary on;
gzip_proxied any;
gzip_types text/css text/plain text/xml text/javascript
           application/javascript application/json application/ld+json
           application/xml application/manifest+json image/svg+xml
           application/wasm;

Brotli is not part of the standard nginx build. With the ngx_brotli module compiled or installed:

brotli on;
brotli_comp_level 5;
brotli_static on;
brotli_types text/css text/plain text/xml text/javascript
             application/javascript application/json application/ld+json
             application/xml application/manifest+json image/svg+xml
             application/wasm;

Precompress static files during the build so the server only has to send them:

brotli -q 11 -k dist/app.js   # writes dist/app.js.br
gzip -9 -k dist/app.js        # writes dist/app.js.gz

brotli_static on serves the .br file. For .gz files you need gzip_static on, from a module that is not built by default (--with-http_gzip_static_module), although many packaged builds include it.

For Apache, use mod_brotli for clients that accept br and mod_deflate for gzip. Both modules send Vary: Accept-Encoding themselves:

<IfModule mod_brotli.c>
  BrotliCompressionQuality 5
  AddOutputFilterByType BROTLI_COMPRESS text/html text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>
<IfModule mod_deflate.c>
  DeflateCompressionLevel 6
  AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>

Behind a CDN, read its documentation before changing the origin. Cloudflare's content compression page, for example, says content to visitors is compressed by default with Zstandard on Free plans, Brotli on Pro and Business and gzip on Enterprise, subject to the browser's Accept-Encoding, and that it requests content from your origin with br, gzip. In that setup the browser-facing result is decided at the edge, and your origin setting mainly affects the origin-to-CDN leg.

Where it runsgzipBrotliPrecompressed files
nginxOff by default; level 1; only text/html listedThird-party ngx_brotli; off by default; level 6gzip_static and brotli_static
Apache 2.4mod_deflate; zlib default levelmod_brotli; quality 5 by defaultRewrite rules shown in the mod_brotli docs
Cloudflare (to visitors)Default on EnterpriseDefault on Pro and Business; Free defaults to ZstandardEdge decides; origin is asked for br or gzip

Defaults as documented on 2026-12-03. Hosting packages often ship their own config, so read the response headers rather than trusting the default.

How do you check that compression is working?

Ask for a specific coding and read the response headers. Run this once per file type, not just for the home page:

curl -s -o /dev/null -D - -H 'Accept-Encoding: br' https://example.com/app.js
curl -s -o /dev/null -D - -H 'Accept-Encoding: gzip' https://example.com/app.js

Then work through this list:

  1. Content-Encoding is present and names the coding you asked for. If the line is missing, the response was sent uncompressed.
  2. Vary includes Accept-Encoding on compressed responses.
  3. Check one URL of each type: an HTML page, a stylesheet, a script, a JSON API response and an SVG.
  4. Compare sizes in the browser. In the DevTools Network panel, the Size column shows the transferred size; with big request rows turned on, the bottom value is the uncompressed size. If both numbers are about equal for a text file, it was not compressed.
  5. Add a Content-Encoding column (right-click the table header, then Response Headers) and sort by it to spot the files without a value.

Why is a file still uncompressed?

Most cases come down to a short list. Match the symptom to the cause:

SymptomLikely causeFix
HTML compressed, CSS and JS notgzip_types left at its text/html defaultAdd the MIME types
Works directly, fails behind a proxygzip_proxied is off and the request carries a Via headerSet gzip_proxied for the cases you need
One script never compressedServed with an unexpected Content-TypeFix the MIME mapping or add that type
Small files uncompressedBelow the minimum lengthExpected; leave it
Some visitors get the wrong coding from a cacheMissing Vary: Accept-EncodingTurn on gzip_vary or add the header
Origin compresses, browser receives something elseThe CDN recompresses at the edgeConfigure compression at the CDN

One security note: compressing a response that contains a secret (such as a token) next to text an attacker can influence may leak information through response size, the class of attack known as BREACH. Apache's module documentation warns about it. Static assets are not affected in this way; for sensitive dynamic pages, ask whoever owns application security.

How to see the effect in TapCub

Suppose the sample site above ran with only HTML compressed and you now add the stylesheet and script types. Those four files drop from 536,040 − 96,142 + 19,330 = 459,228 bytes on the wire to 142,440 at gzip 6. TapCub does not inspect response headers or audit compression, so confirm that with curl or DevTools. What TapCub measures is whether real visitors then saw the page sooner.

TapCub performance cards showing P75 LCP, CLS, INP, FCP and TTFB with the share of good samples
Demo data: each Core Web Vitals card shows P75, the share rated good and the number of samples.
  1. Mark the release. In Configuration › Annotations, add a single-day annotation of type Release, such as "Brotli for CSS and JS", so later readers know why the trend moved.
  2. Read FCP and LCP at P75. Open Monitoring › Performance. Stylesheets and head scripts hold back the first paint, so first contentful paint is the card most likely to respond.
  3. Check the loading breakdown. It splits a load into backend, network and frontend. The network part is the download of the HTML response, so it reflects HTML compression; slower on-request compression would show in backend time.
  4. Compare two date ranges on the same page. This report has no previous-period comparison, so note P75 and sample counts for the week before the annotation, then for the week after. Use Breakdown by device, since phones on slow networks gain most from smaller files.

If the numbers barely move, bytes were not the bottleneck; how to speed up a website ranks other fixes, and removing unused JavaScript cuts bytes that compression only shrinks.

FAQ

Is Brotli better than gzip?

For size, usually yes at comparable effort. On our four text files, Brotli 5 produced 134,959 bytes against 142,440 for gzip 6, and compressed faster; Brotli 11 reached 121,929 but needed far more CPU. Serve Brotli to clients that accept br and keep gzip as the fallback for everything else.

Should I compress images with gzip or Brotli?

No for JPEG photographs, PNG and WebP, which already carry their own compression; our PNG shrank by 0.3% and the WebP file grew slightly. SVG is the exception because it is XML text, so compress it. To make raster images smaller, change dimensions, format or quality instead.

How do I know if gzip is enabled on my site?

Request a file with Accept-Encoding: gzip using curl -s -o /dev/null -D - and look for Content-Encoding: gzip in the response. In browser DevTools, compare the transferred and uncompressed sizes in the Network panel. Test CSS, JavaScript and JSON as well as the HTML page.

Does text compression improve Core Web Vitals?

It can help first contentful paint and largest contentful paint when render-blocking CSS, scripts or the HTML itself take a noticeable time to download, especially on slow mobile connections. It does little when images dominate the page weight or when the server is slow to respond. Confirm with field data before and after.

What about Zstandard?

Zstandard is another HTTP content coding, sent as zstd, and some CDNs and browsers support it. Treat it as an addition, not a replacement: check what your server or CDN offers, keep gzip available, and compare sizes and response times on your own files before switching anything.

Sources

Filed underAnalytics

Was this article helpful?

We use your answers to fix and expand this page.

Emma Collins

Product Analyst

Focuses on event analysis, conversion funnels, and retention, using clear metric definitions and structured analysis to explain product performance.

Check whether visitors got a faster first paint

Real-user Core Web Vitals at P75 by page and device, with sample counts and release annotations on your trend charts.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics