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, […]
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:
If your WordPress site is hosted on an Apache server, you can enable Gzip compression by adding the following lines to your .htaccess file:
.htaccess file (found in the root directory of your WordPress installation).<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>If your WordPress site is hosted on Nginx, modify your server configuration file:
/etc/nginx/nginx.conf or /etc/nginx/sites-available/default).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
sudo systemctl restart nginxTest Gzip compression.
If you don’t want to edit server files, use a plugin:
After enabling Gzip compression, test if it’s working using these tools:
John O'Connor is the founder and principal engineer of Web Lifter, a Brisbane software studio building custom software, AI systems, and structured data for Australian SMBs. He has spent over eight years shipping production AI and backend systems, and writes about what actually holds up once the demos are over. Everything published here is drawn from systems running in production for real clients.