Gzip Compression htaccess Code

Gzip Compression htaccess Code

This code snippet will compress your website using gzip compression. Adding the following code to your htaccess file will compress output for files from your web server. This type of method becomes extremely useful for optimizing speeds on your website.

For users operating on a cpanel system, it may be ideal to add this code via the file manager. Users without cpanel can simply add this to the htaccess file using FTP.

Always backup your htaccess file before making these types of changes! This code is clean, but there is always a chance that your server won’t allow it, or that it may cause issues on your site.

To compress your file output with gzip, add the following to your htaccess file:

# compress text, html, javascript, css, xml:
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

# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>

 

Comments

Back to Blog Join Newsletter