Gzip compression on Apache using .htaccess

0

As per http://gtmetrix.com/enable-gzip-compression.html i'm trying to enable gzip compression on apache webserver adding code mentioned below in .htaccess, but it's not working ; can you please suggest how to fix this?

<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 image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>

Pawan Mude

Posted 2015-06-01T10:31:26.180

Reputation: 165

1Are you sure you're running mod_deflate? Depending on your OS, run httpd -M or apache2ctl -M. – ice13berg – 2015-06-01T10:37:04.403

No I'm not running mod_deflate. is there any way other than running mod_deflate? – Pawan Mude – 2015-06-03T14:33:36.337

1Well, if you're not running mod_deflate, your IfModule mod_deflate.c statement isn't being processed - so that's why it's not working. – ice13berg – 2015-06-03T22:47:48.487

Answers

1

So, you have two options. First, I would encourage you to just load the mod_deflate module. Add the following line to your httpd.conf file.

LoadModule deflate_module modules/mod_deflate.so

Otherwise, there is an alternative - mod_gzip. It is a an external extension that you'll have to download the source code, compile, and load using a line in your httpd.conf file. Something like:

LoadModule gzip_module mod_gzip.so

Here are two StackExchange threads that discuss mod_gzip vs. mod_deflate.

Here and Here

Good luck.

ice13berg

Posted 2015-06-01T10:31:26.180

Reputation: 216