Skip to main content

Performance fix

How to Enable Gzip / Brotli Compression

Compress text responses (HTML, CSS, JS) so they transfer much smaller.

Last updated by the SlapMyWeb team

Difficulty
Medium
Impact
High
Time
15 min

Before

# nginx: no compression configured

After

# nginx
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
brotli on;
brotli_types text/css application/javascript application/json;
Before and after code for: How to Enable Gzip / Brotli Compression

Text files like HTML, CSS and JavaScript compress very well, so serving them uncompressed wastes most of the bytes you send. Turn on Brotli or Gzip in your server or CDN, then confirm the response carries a content-encoding header. Transfer size drops sharply with no change to your code; web.dev reports rates often as high as 70 to 90 percent for larger text files.

Why it matters

Text-based files compress extremely well. Enabling Brotli or Gzip on the server cuts transfer size sharply with no change to your code (web.dev reports compression rates often as high as 70-90% for larger text files): one of the highest-leverage performance wins available.

How to fix it

  1. Turn it on at the server

    Enable Brotli (preferred) or Gzip in your web server / CDN for text MIME types.
  2. Verify the header

    Check the response includes content-encoding: br (or gzip) for HTML/CSS/JS.

The code

Beforenginx
# nginx: no compression configured
Afternginx
# nginx
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
brotli on;
brotli_types text/css application/javascript application/json;

On your platform

WordPress

Most managed hosts enable this by default. If not, a caching plugin or your host's control panel can turn on Gzip/Brotli.

Next.js

Next.js gzip-compresses by default; if you sit behind nginx/Cloudflare, enable Brotli there instead.

Sources

Check your site with our free tool

HTTP Header Checker

What the terms mean

Check it free

Fixed that one.
Now find the rest.

A free audit puts every issue on your site into a fix plan, most urgent first, and links each one to its guide.

Run a free audit
First audit freeNo card neededLive scan progress