Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared Managed Cloud India
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Best lists Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Speed & performance · Guide

How to Enable Gzip or Brotli Compression for WordPress

Short answer

To enable Gzip or Brotli compression for WordPress, turn it on at the server or CDN level, not inside WordPress itself. On Apache, add mod_deflate rules to .htaccess; on NGINX, set gzip on; in Cloudflare, choose Enable Brotli and Gzip compression in a Compression Rule. Brotli is preferred where it is supported, with Gzip as the fallback, and you can confirm the result in the Content-Encoding response header.

Key takeaways

  • Brotli is the preferred algorithm where it is supported, with Gzip as the fallback for older clients.
  • In the web.dev example, a 225 KB JavaScript bundle fell to 61.6 KB with Gzip and 53.1 KB with Brotli.
  • Compress HTML, CSS, JavaScript, JSON, XML, and SVG, and leave images, video, and audio alone.
  • A compressed response must carry a Vary: Accept-Encoding header so caches keep each version apart.
  • Check the Content-Encoding header in DevTools or with curl after every change.

What is Gzip or Brotli compression in WordPress?

Gzip and Brotli shrink text files such as HTML, CSS, and JavaScript on the server, and the browser expands them on arrival.

The browser lists the formats it can decode in an Accept-Encoding header, and the server picks one and names it in the Content-Encoding header. MDN shows a typical browser request as Accept-Encoding: gzip, deflate, br, zstd.

Compression only changes the transfer size. MDN notes that content encoding compresses content without losing information about the original media type, so the browser rebuilds the same file before it renders the page.

Compression is one part of a faster site. How to speed up WordPress covers the other steps that sit next to it, such as caching and image sizes.

Should you choose Gzip or Brotli?

Use Brotli first when your server or CDN supports it, and keep Gzip as the fallback for older clients.

In a web.dev codelab, a 225 KB JavaScript bundle fell to 61.6 KB with Gzip and to 53.1 KB with Brotli. The same codelab reports Brotli files 14% smaller than Gzip for JavaScript, 21% smaller for HTML, and 17% smaller for CSS.

FeatureGzipBrotli
AlgorithmDEFLATE, using LZ77 with a 32-bit CRC, as MDN describes itBrotli, defined in RFC 7932, as MDN describes it
Size in the web.dev example (225 KB bundle)61.6 KB, per web.dev53.1 KB, per web.dev
Smaller than GzipBaseline14% for JavaScript, 21% for HTML, 17% for CSS, per web.dev
Compression level range1 to 9, per ApacheSet by the server or CDN, with higher levels taking longer
HTTPS neededNoYes, per web.dev
Browser supportEvery browserAll modern browsers, per web.dev

Brotli needs HTTPS. web.dev says a server must support HTTPS to use Brotli, so sites still on plain HTTP should fix that first or stay on Gzip.

Compression shrinks files, but it does not remove code the page never runs. How to remove unused CSS in WordPress covers that separate step.

What do you need before you start?

You need admin access to WordPress, access to your hosting panel or server files, and a backup of any file you plan to edit.

  • Find your server type first: Apache, NGINX, LiteSpeed, or Cloudflare in front.
  • Check whether compression is already on, since many hosts enable it by default.
  • Back up .htaccess or nginx.conf before you edit it, so you can undo a typo in seconds.
  • Use HTTPS if you want Brotli, since web.dev says a server must support HTTPS to use it.

Plan on 10 to 30 minutes for one method, plus a few minutes to check the headers after each change.

Ask your host which server runs your site if the panel does not say. The method below that matches your server is the only one you need.

How do you enable Gzip on Apache with .htaccess?

On Apache, add mod_deflate rules to the .htaccess file in your WordPress root folder.

  1. Download a copy of .htaccess first, in File Manager or by SFTP.
  2. Open .htaccess in the WordPress root folder, above the wp-admin and wp-content folders.
  3. Paste the block below at the top of the file.
  4. Save the file and load your home page to confirm the site still works.
  5. Check the headers as described in the checking section below.
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json image/svg+xml
DeflateCompressionLevel 6

Apache describes mod_deflate as the DEFLATE output filter that compresses output before it is sent to the client. The level runs from 1 to 9, and Apache notes that a higher value gives better compression but needs more CPU time.

Apache also sends a Vary: Accept-Encoding header with compressed responses, so shared caches keep the compressed and plain versions apart. The Apache mod_deflate docs explain that this stops a cache from sending compressed content to a client that cannot decode it.

If your host runs LiteSpeed, use the plugin section below instead of editing .htaccess by hand. LiteSpeed servers have their own compression switch, and your host may already have it turned on.

How do you enable Gzip on NGINX?

On NGINX, turn on Gzip in the http block of nginx.conf with gzip on and a gzip_types list.

  1. Open /etc/nginx/nginx.conf in your editor, and make a backup copy first.
  2. Add the block below inside the http block, not inside a single server block, so it covers every site on the server.
  3. Run nginx -t to check the file for errors.
  4. Reload NGINX with systemctl reload nginx or the command your host documents.
gzip on;
gzip_vary on;
gzip_min_length 1000;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;

The NGINX gzip module is off by default, so a fresh install sends text uncompressed until you add these lines. The NGINX gzip module docs list gzip as off by default, and MDN names ngx_http_gzip_module as the NGINX compression module.

The gzip_vary line adds Vary: Accept-Encoding, so caches do not hand a Gzip file to a browser that never asked for one. The NGINX gzip module docs describe gzip_vary as the switch that emits that header.

For Brotli on NGINX, ask your host or put Cloudflare in front. The next section covers the Cloudflare route.

How do you enable Brotli in Cloudflare?

In Cloudflare, create a Compression Rule and choose Enable Brotli and Gzip compression for your zone.

  1. Open your zone in the Cloudflare dashboard.
  2. Go to Compression Rules and create a rule.
  3. Set the rule to match the requests you want compressed, such as all traffic to the zone.
  4. Choose Enable Brotli and Gzip compression and save the rule.
  5. Wait a few minutes, then check the headers on a live page.

Cloudflare says Brotli is the preferred algorithm in this setting, and it falls back to Gzip or to uncompressed data. The settings page was updated on 16 April 2026, as of November 2026.

If you list only Gzip, Brotli, or Zstandard with no fallback, a visitor whose browser matches none of them gets no compression. Cloudflare advises adding Auto to the list so a fallback exists.

How to set up Cloudflare for WordPress walks through connecting a site to Cloudflare before you touch compression.

How do you enable compression with a WordPress plugin?

A caching plugin can switch compression on for you, but it only works when the server behind it supports the module it needs.

The LiteSpeed blog notes that LiteSpeed Cache and WP Super Cache both cache and serve compressed content, while WP Super Cache supports Gzip and LiteSpeed Cache supports both Gzip and Brotli.

LiteSpeed added Brotli for dynamic responses in version 5.3. It can also convert a cached Gzip page to Brotli and save the converted copy after 10 repeat requests, as the LiteSpeed blog explains.

After you install a caching plugin, look for its Gzip or compression toggle, turn it on, and save. Then check the response headers, since a toggle that changes nothing means the server module is missing.

WordPress Site Health sits under Tools > Site Health in the dashboard. WordPress.org says it checks the health of your site and reports configuration problems.

How do you check that compression is working?

Open DevTools, load a page, click a CSS or JavaScript file, and look for Content-Encoding: gzip or Content-Encoding: br in the response headers.

web.dev gives the same check: read the Content-Encoding field in the Chrome DevTools Network tab. A missing Content-Encoding header on a text file means that file arrived uncompressed.

curl -sI -H "Accept-Encoding: gzip, br" https://your-site.com/ | grep -i "content-encoding"

The output should show content-encoding: br or content-encoding: gzip. Test the home page and one CSS file, since a plugin may compress one and miss the other.

Run PageSpeed Insights after the change. The Lighthouse Enable text compression audit lists text resources that should be compressed, as web.dev explains. web.dev also notes that Gzip can reduce the transfer size of text resources by about 70%.

Compression shrinks the transfer size, but it is only one input to the scores. How to pass Core Web Vitals in WordPress puts it in context.

It does not fix a slow server response on its own. What is TTFB explains the server wait that compression cannot shrink.

What mistakes should you avoid?

The most common mistake is compressing files that are already compressed, such as JPEG images, video, and audio.

  • Compressing images, video, or audio. MDN warns that a second round of compression may increase the size of already-compressed data, and it names JPEG as an example.
  • Forgetting the Vary header. MDN states that a server must send a Vary header with at least Accept-Encoding so caches store each version apart.
  • Setting the level to the maximum on dynamic pages. web.dev notes that higher levels take longer and can delay the response while the file compresses.
  • Testing only the home page. Check a CSS file, a JavaScript file, and a post page too, since each one can take a different path through the server.
  • Editing the live file with no backup. One typo in .htaccess can return a 500 error on every page, so keep the copy you downloaded.

Images need a different fix. How to serve images in next-gen formats in WordPress covers smaller image files instead of compressing them again.

Frequently asked questions

Does WordPress enable Gzip or Brotli compression by itself?

No. WordPress does not compress responses on its own. Compression happens at the server or CDN level, through Apache mod_deflate, the NGINX gzip module, a LiteSpeed setting, or a Cloudflare Compression Rule. A caching plugin can add the rules for you, but the server still has to support them.

Is Brotli always better than Gzip for WordPress?

Brotli usually makes smaller files, and web.dev reports it 14% smaller than Gzip for JavaScript, 21% smaller for HTML, and 17% smaller for CSS. It needs HTTPS and server support, so keep Gzip as the fallback for clients and setups that lack Brotli.

Will compression break my WordPress site?

Compression only changes how files travel, not the files themselves, so a correct setup does not change how pages look or work. Problems usually come from a typo in .htaccess or nginx.conf, so back up the file first and check the site right after saving.

Why does PageSpeed Insights still flag text compression after I enabled it?

The flag usually means some files are still uncompressed, often CSS or JavaScript from a plugin or CDN that sits outside your rule. Check the Content-Encoding header on each flagged file, widen the rule to cover it, and purge the cache before you run the audit again.

Should I compress images with Gzip or Brotli?

No. JPEG, PNG, WebP, and video files are already compressed, so a second round of compression saves almost nothing and can make a file larger. Compress text files such as HTML, CSS, JavaScript, and SVG, and shrink images with a modern format instead.

Sources

  1. Minify and compress network payloads with brotli web.dev
  2. Compression in HTTP MDN Web Docs
  3. Accept-Encoding header MDN Web Docs
  4. Content-Encoding header MDN Web Docs
  5. Compression Rules settings Cloudflare Docs
  6. mod_deflate Apache HTTP Server Documentation
  7. LiteSpeed Web Server Version 5.3 New Features LiteSpeed Blog
  8. Fix an overloaded server web.dev

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

WPLegible editors

Researched from the primary sources listed above and checked against our editorial rules. About the site · How we test