Enable GZIP Compression on Apache

Enable GZIP Compression on Apache

GZIP is an automatic process where the server compresses your HTML, CSS, and JavaScript files for you in-transit. On most web hosts, all you have to do it enable it. Here’s how using your .htaccess file for Apache servers.

There’s a “default” way of enabling GZIP using .htaccess. Instructions and code for that are here. If that doesn’t work for you and you’re using an Apache web server, here’s another way to achieve the same thing.

Enable GZIP on Apache

For the most part, all you have to do is add the following to your .htaccess file.

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Save the .htaccess file and then refresh your webpage. Once that’s done, you can check to see if your compression is working using this Gzip compression testing tool from our friends at Feed the Bot.

If this script doesn’t work, you might try the code found in this other JDM Labs article.

Leave a Reply