Home / Fix guides / Speed and Core Web Vitals

How to enable text compression (gzip and Brotli)

Text compression shrinks your HTML, CSS and JavaScript before the server sends them, so pages load faster. You turn it on in your host, CDN or server settings, then confirm the response carries a content-encoding: br or gzip header.

If a speed test tells you to "Enable text compression", your server is sending text files at full size. Every visitor downloads more data than needed, which hurts most on phones and slow connections. The fix is usually a single setting, and it is one of the cheaper speed wins available.

What the problem is

When a browser asks for a page, it says which compression formats it understands (usually gzip and Brotli). A server with compression on shrinks text files before sending them, and the browser unpacks them instantly. A server without it sends the files at full size.

Text compresses very well because code and markup are full of repeated patterns. HTML, CSS, JavaScript, JSON, SVG and XML files often shrink dramatically. Brotli (br) usually produces smaller files than gzip, but browsers only use it over HTTPS. Gzip works everywhere, so most sites offer both.

What you see as an owner: a PageSpeed Insights or Lighthouse warning called "Enable text compression", slow loading on mobile, and a heavy network transfer in browser tools.

Why it matters

Smaller files arrive sooner, so the page appears sooner. That helps Core Web Vitals such as Largest Contentful Paint, which Google uses as one of many signals for search. It also helps visitors: slow pages tend to lose people before they read, call or buy. For mobile visitors on weak signal, the saving is the most noticeable.

There is usually no security or trust downside to turning it on for ordinary pages. Compression costs the server a small amount of processing, which is normally negligible.

How to check if your site has it

You have three free options.

  1. PageSpeed Insights. Enter your address at pagespeed.web.dev. If compression is missing, "Enable text compression" appears under Diagnostics or Opportunities, with the files listed.
  2. Browser developer tools. Open your page, press F12, go to the Network tab, reload, and click your main page or a CSS or JS file. Under Response Headers, look for content-encoding. The value gzip or br means it is on. No header means it is off. The Size column also shows transferred size against full size.
  3. A command line check (for developers or the curious):
curl -s -D - -o /dev/null -H 'Accept-Encoding: gzip, br' https://www.example.com/

Look for a content-encoding line in the output. Test a CSS or JavaScript file too, because pages can be compressed while assets are not.

How to fix it in general

Compression is switched on where your site is served from. Work out which of these applies, starting from the front of the chain:

  • A CDN or proxy in front of the site (Cloudflare, CloudFront, others): enable it there.
  • Managed hosting or a control panel: look for a speed or optimization setting.
  • Your own server (Nginx, Apache, IIS): edit the server configuration or ask whoever manages it.

Whichever you use, compress text types only: HTML, CSS, JavaScript, JSON, SVG, XML and plain text. Do not bother compressing JPEG, PNG, WebP, AVIF, MP4, WOFF2 fonts or ZIP files, since they are already compressed and you gain nothing.

Common platforms

Menu names change between versions and themes, so treat these as pointers.

PlatformWhere to look
CloudflareSpeed, then Optimization, then Content Optimization, where Brotli is a toggle. Cloudflare compresses eligible text by default.
cPanelSoftware section, "Optimize Website", then compress all content or specified MIME types.
WordPressOften handled by the host. Otherwise a caching plugin or the server config.
Nginxgzip directives in nginx.conf. Brotli needs an extra module.
Apachemod_deflate for gzip, mod_brotli for Brotli (Apache 2.4.26 or newer).
IISStatic and dynamic content compression features, which must be installed as IIS role services.
AWS CloudFront"Compress objects automatically" in the cache behavior.

For step-by-step help, see our guides for WordPress and Cloudflare.

A minimal Nginx example (gzip, placed in the http or server block):

gzip on;
gzip_vary on;
gzip_comp_level 5;
gzip_types text/css application/javascript application/json image/svg+xml application/xml;

Nginx compresses text/html by default once gzip on is set. A minimal Apache example, in .htaccess or the site config:

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json image/svg+xml application/xml
</IfModule>

Back up the file before editing, and ask your host if you are unsure. On WordPress, the .htaccess route only applies to Apache servers. If your host uses Nginx, the change happens in the server config, which is usually the host's job.

How to confirm the fix worked

  1. Clear any cache: your caching plugin, your CDN cache, and your browser cache.
  2. Run the curl command above, or reload the page with the Network tab open, and look for content-encoding: br or gzip on your page, a CSS file and a JavaScript file.
  3. Look for a vary: Accept-Encoding header too. It tells caches to store compressed and uncompressed versions separately.
  4. Run PageSpeed Insights again. The warning should disappear. Results can vary slightly between runs.

If the header is still missing, something between the server and the visitor may be undoing it. Common causes are a proxy or security layer that strips the header, a second compression setting conflicting with the first, or the file type missing from the list of types to compress.

How to stop it coming back

Compression often disappears silently after a change of host, a server upgrade, a new CDN or a rebuilt server config. Re-check the headers after any of those. Keep a note of where compression is enabled (CDN, host panel or config file) so the next person knows where to look.

SiteMonday checks this in week 4, speed and Core Web Vitals, which ends with a written report and a ranked fix list. Fixing the problem is up to you or your developer. Compression pairs well with shrinking files in the first place, so it is worth reading about unminified CSS and JavaScript next.

Step by step for your platform

Questions

Should I use gzip or Brotli?

Use both if you can. Brotli usually gives smaller files over HTTPS, and gzip is the fallback for older clients. If you can only enable one, gzip is fine and nearly universal.

Will text compression slow my server down?

It uses a little processing power, but for normal sites the cost is small compared with the time saved sending smaller files. Many hosts and CDNs also cache compressed copies.

Do I need to compress images?

No. JPEG, PNG, WebP and AVIF are already compressed, so text compression adds nothing. Use properly sized and optimized images instead.

Why does PageSpeed still say compression is missing after I turned it on?

A cache or CDN may still serve the old uncompressed version, or certain file types may not be on the compress list. Clear caches and check the `content-encoding` header on the specific files named in the report.

Does Cloudflare compress my site automatically?

Cloudflare compresses eligible text content by default, and Brotli can be toggled in its optimization settings. If your own server sends files uncompressed, check that Cloudflare is actually proxying the traffic.

Is this a problem I can fix without a developer?

Often yes, if your host or CDN has a toggle. If it needs a server config change on your own server, ask your host or developer.

Related problems