Enabling gzip compression is one of the highest-impact, lowest-effort performance changes you can make to an Apache site — often cutting transferred size by 60-80% for text-based content.
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript
AddOutputFilterByType DEFLATE application/javascript application/json
AddOutputFilterByType DEFLATE application/xml image/svg+xml
# Don't compress already-compressed formats - wasted CPU for no benefit
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|zip|gz)$ no-gzip
</IfModule>
sudo a2enmod deflate sudo systemctl reload apache2 # Verify it's actually working curl -H "Accept-Encoding: gzip" -I https://example.com | grep -i content-encoding
Brotli: The Newer, Better Option
If your Apache build supports mod_brotli, it generally compresses text content 15-20% smaller than gzip at the same speed — worth enabling alongside gzip as a fallback for clients that don’t support Brotli.