Guides /WordPress
WordPress

Enable GZIP Compression on WordPress: Smaller Files, Faster Pages

August 24, 20257 min readHostBible Team

GZIP compression reduces the size of files transferred between your server and visitors' browsers. Text-based content, HTML, CSS, and JavaScript, compresses by 60–80% with GZIP. A page that transfers 500KB of text assets transfers around 120KB with compression enabled. The decompression happens in the browser in milliseconds and is transparent to the user. Most modern servers support GZIP; many don't have it configured to cover all the right content types.

How GZIP compression works

When a browser sends an HTTP request, it includes an Accept-Encoding: gzip, deflate, br header indicating which compression formats it supports. If the server has GZIP enabled, it compresses the response before sending and adds a Content-Encoding: gzip response header. The browser decompresses the response automatically. The entire exchange is invisible to the user, they just experience a faster page load.

Brotli (br in the Accept-Encoding list) is a newer compression algorithm developed by Google that typically achieves 15–25% better compression ratios than GZIP for text content. All modern browsers support Brotli, and LiteSpeed servers support it natively. Where Brotli is available, it's preferable to GZIP. Where it isn't, GZIP remains highly effective.

How to verify compression is enabled

Before making changes, check whether compression is already active on your server. Several methods:

Browser DevTools. Open Chrome DevTools, go to the Network tab, reload the page, and click on an HTML or CSS response. In the Response Headers section, look for content-encoding: gzip or content-encoding: br. If present, compression is active for that resource.

PageSpeed Insights. The "Enable text compression" recommendation only appears if PageSpeed detects that text resources are being served uncompressed. If you don't see this recommendation, your server is already compressing responses adequately.

GTmetrix. The "Compress components with GZIP" check in GTmetrix's audit results tells you whether your key resources are being compressed and which content types are missing compression.

Enabling GZIP via .htaccess (Apache and LiteSpeed)

On Apache or LiteSpeed servers, add the following to your .htaccess file. Place it above the WordPress rewrite rules:

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, text, XML, and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
</IfModule>

The <IfModule mod_deflate.c> wrapper ensures the directive is only applied if mod_deflate is loaded, it won't cause a 500 error if the module is absent. SVG images are included because they're XML-based text files that compress well. Standard raster images (JPEG, PNG, WebP) are intentionally excluded because they're already compressed and GZIP on them wastes CPU with negligible benefit.

Enabling compression via the hosting control panel

Many hosts provide GZIP as a toggle in the control panel, typically under a Performance, Optimization, or Speed section. cPanel hosting sometimes includes this under "Optimize Website" or within a performance settings area. Enabling it at the control panel level applies compression at the server configuration level rather than via .htaccess, which is slightly more efficient and applies to all sites on the account rather than per-directory.

If your host's control panel offers this option, it's preferable to the .htaccess approach. The .htaccess method is a reliable fallback when server-level configuration access isn't available.

GZIP via Nginx

If your site runs on Nginx (common on VPS environments), GZIP configuration goes in the Nginx server block or http block, not .htaccess. A standard configuration:

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json
           application/javascript application/rss+xml
           application/atom+xml image/svg+xml;

gzip_comp_level 6 is a good balance between CPU usage and compression ratio. Levels above 6 produce diminishing returns on compression ratio while increasing CPU cost per request. gzip_vary on adds the Vary: Accept-Encoding header, which tells caches to store separate copies for compressed and uncompressed versions.

Enabling via a WordPress plugin

If you can't modify server configuration directly, caching plugins can handle response compression through PHP. WP Rocket's "Enable GZIP compression" option uses PHP's output buffering with ob_gzhandler to compress responses. W3 Total Cache includes a similar option under Browser Cache settings.

PHP-level compression is less efficient than server-level compression because PHP has to execute before the compression can be applied, whereas server-level compression happens after PHP has finished and handed the response to the web server. Use the plugin approach as a fallback when .htaccess modification and control panel options aren't available, not as a first choice.

What GZIP doesn't help with

GZIP has minimal benefit, and can actually produce slightly larger output, on already-compressed binary formats. JPEG, PNG, WebP, and AVIF images are already compressed as part of their format specification. Video files (MP4, WebM) and audio files are similarly pre-compressed. Applying GZIP to these file types wastes server CPU for negligible or negative file size benefit.

Correctly configured GZIP excludes binary formats automatically by restricting compression to text MIME types. If you use the .htaccess block shown above, this is already handled, only text-based content types are included in the AddOutputFilterByType directives. Don't add image or video MIME types to your compression rules.

Brotli compression on LiteSpeed, no configuration required

HostBible's LiteSpeed servers support Brotli compression natively, more efficient than GZIP and enabled automatically, with no .htaccess changes needed on your end.

View Hosting Plans