developers

GZIP Compression

8 August 2025

Enabling Gzip compression on your WordPress website can significantly improve page load speeds by reducing the size of HTML, CSS, and JavaScript files sent from your server to users. Here are a few ways to enable Gzip compression:

Method 1: Enable Gzip via .htaccess (Apache)

If your WordPress site is hosted on an Apache server, you can enable Gzip compression by adding the following lines to your .htaccess file:

Steps

  1. Connect to your server via FTP or use the File Manager in cPanel.
  2. Locate and edit the .htaccess file (found in the root directory of your WordPress installation).
  3. Add the following code at the beginning or end of the file:
Apache
<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 text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
</IfModule>
  1. Save the file and clear your cache.
  2. Test if Gzip compression is working (use online tools like Gzip Compression Test).

Method 2: Enable Gzip via Nginx

If your WordPress site is hosted on Nginx, modify your server configuration file:

Steps

  1. Connect to your server via SSH.
  2. Open the Nginx configuration file /etc/nginx/nginx.conf or /etc/nginx/sites-available/default).
  3. Add or modify the following lines:
Nginx
gzip on;
gzip_comp_level 5;
gzip_types text/plain text/css text/javascript application/javascript application/x-javascript application/json application/xml application/rss+xml image/svg+xml;
gzip_vary on;

Save the file and restart Nginx

Bash
sudo systemctl restart nginx

Test Gzip compression.

Method 3: Enable Gzip Using a WordPress Plugin

If you don’t want to edit server files, use a plugin:

  1. WP Rocket (Premium)
    • Go to Settings > WP Rocket.
    • Enable Gzip compression in the File Optimization tab.
  2. W3 Total Cache (Free)
    • Go to Performance > Browser Cache.
    • Check Enable HTTP (gzip) compression.
    • Save settings and clear cache.
  3. Autoptimize (Free)
    • Go to Settings > Autoptimize.
    • Enable Optimise HTML/CSS/JS (Gzip is automatically applied).

Testing If Gzip Is Enabled

After enabling Gzip compression, test if it’s working using these tools: