Skip to main content
SlapMyWeb

Performance fix

How to Enable Gzip / Brotli Compression

Compress text responses (HTML, CSS, JS) so they transfer 60-80% smaller.

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 usually drops by 60 to 80 percent with no change to your code.

Why it matters

Text-based files compress extremely well. Enabling Brotli or Gzip on the server cuts transfer size by 60-80% with no change to your code: 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

Fixed that one.
Now find the rest.

A free audit ranks every issue on your site by the score points it costs, and links each one straight to its guide.

Run a free audit
Free foreverNo signupLive scan progress
How to Enable Gzip / Brotli Compression | SlapMyWeb