Mod_deflate not reflecting changes

Hi There,

I followed this tutorial https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-mod_deflate-on-centos-7 and created a file under path

/etc/httpd/conf.d/mod_deflate.conf

<filesMatch "\.(js|html|css)$">
    SetOutputFilter DEFLATE
</filesMatch>

Restarted the server, but the compression doesnt seems to be working, is there anything else I need to do to enable this.

Note: httpd -t -D DUMP_MODULES successfully results the module:

deflate_module (shared)

Appreciate your help.

Try wrapping directives in mod_deflate.conf like this:

<IfModule mod_deflate.c>
 <filesMatch "\.(js|html|css)$">
    SetOutputFilter DEFLATE
 </filesMatch>
</IfModule>

Or try it another way:

<IfModule mod_deflate.c>
  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/json
  AddOutputFilterByType DEFLATE text/md
  AddOutputFilterByType DEFLATE text/pl
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
</IfModule>

Hi @ramin thanks for the details, it worked and now the compression is enabled for the entire site. However the Ajax calls have stopped working, with this compression. Every time the ajax call is made it will freeze the request and the request will not go further, please find the below image.

Any idea what could be happening here.

I am using Codeignitor as the framework.

Now you’re biting off more than I can chew. :wink:

My best guess is that in addition to DEFLATE directives in the <IfModule mod_deflate.c> section, you need to work on headers for encoding types (mod_headers is surely loaded already). A common snafu is content that’s already compressed getting the gzip treatment a second or third time and something goes wrong, least of which is wasted CPU.

Search and research headers with mod_deflate. In your mod_deflate.conf you probably need something along the lines of…

<IfModule mod_deflate.c>
..
..
</IfModule>

<IfModule mod_headers.c>
    # Serve gzip compressed CSS and JS files if the client accepts gzip
    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{REQUEST_FILENAME}\.gz" -s
    RewriteRule "^(.*)\.(css|js)"         "$1\.$2\.gz" [QSA]

    # Serve correct content types and prevent double compression
    RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
    RewriteRule "\.js\.gz$"  "-" [T=text/javascript,E=no-gzip:1]

    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type
      Header append Content-Encoding gzip
    </FilesMatch>
</IfModule>

Just for grins copy/paste this snippet, restart Apache and see if Ajax calls stop crashing.

2 Likes

Yes it worked, thanks a lot. Really appreciated!!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.