How To Deliver Files With gzip On Apache Servers

If you’ve gotten to this page, you probably already know a little bit about gzip. If not, its basically just a way to compress your files for delivery to your user’s browsers. Although gzip can work with any file type, its only recommended on text based files, meaning HTML, CSS, and JavaScript. There are a lot of different ways to enable gzipping of your files, but the fastest and simplest is to just add a few lines to your .htaccess file. The following is what I use:
## gzip
<IfModule mod_mime.c>
 AddType application/x-javascript .js
 AddType text/css .css
</IfModule>
<IfModule mod_deflate.c>
 AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript
 <IfModule mod_setenvif.c>
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 </IfModule>
 <IfModule mod_headers.c>
  Header append Vary User-Agent env=!dont-vary
 </IfModule>
</IfModule>
The best way to check to make sure that it’s now enabled is to have Google crawl your site using Page Speed Insights. This tool is great because it will not only let you know if the gzipping is working correctly, but will also point out other page speed optimizations you can make to your site.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

One thought on “How To Deliver Files With gzip On Apache Servers