1

I've done almost everything on the internet to gzip my content. It does not seem to work. I've done so much that I can't possibly put everything I've tried here, so here's some of the things I've tried:

I've tried adding this into my .htaccess and I also tried adding it into my apache2.conf and restarting apache.

<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>

They both don't work. I'm on an AWS EC2 Ubuntu server with Apache.

11
  • When you say 'gzip my content', I assume you mean compressing files as they are served from the webserver? May 2, 2016 at 20:00
  • @SomeoneSomewhere Yes, you're right.
    – Edward
    May 2, 2016 at 20:00
  • Anyone know anything about this?
    – Edward
    May 6, 2016 at 20:08
  • did you check the apache module deflate is enabled May 8, 2016 at 13:04
  • @TamilSelvan Yes, mod deflate and gzip are enabled
    – Edward
    May 8, 2016 at 15:44

2 Answers 2

0

I found the answer... finally!

It was in this code that was something like this:

SetEnvIfExpr no-gzip

It was in my apache2.conf file. Once I removed that code, it worked!

0

Apache2 say:

One further directive AddOutputFilterByType is still supported, but deprecated. Use dynamic configuration instead.

First I thought that better to use AddOutputFilter directive.


However solution found at How to enable gzip compression on Apache show enough anew way to configure mod_deflate.

Lookalike:

<IfModule mod_mime.c>
 AddType application/x-javascript .js
 AddType text/css .css
</IfModule>
<IfModule mod_deflate.c>
 SetOutputFilter DEFLATE
  <IfModule mod_setenvif.c>
   SetEnvIfNoCase Request_URI \.(?:rar|zip)$ no-gzip dont-vary
   SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary
   SetEnvIfNoCase Request_URI \.(?:avi|mov|mp4)$ no-gzip dont-vary
   SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
  </IfModule>
 <IfModule mod_headers.c>
  Header append Vary User-Agent env=!dont-vary
 </IfModule>
</IfModule>

Read subj for a varies.


Example of Apache 1.3 mod_gzip module mean just:

  <ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
  </ifModule>

look more / found here

And my humble opinion that the part about really old browsers is not very reliable part of your .htaccess

3
  • No sorry, it says gzip is still not enabled.
    – Edward
    May 10, 2016 at 15:25
  • can you show your response headers?
    – swift
    May 13, 2016 at 16:00
  • If you're wondering about the "Accept-Encoding", this is what it says: Accept-Encoding: gzip, deflate
    – Edward
    May 14, 2016 at 3:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .