How can I use gzip compression for .css and .js files on my websites? How can I use gzip compression for .css and .js files on my websites? apache apache

How can I use gzip compression for .css and .js files on my websites?


AddOutputFilterByType DEFLATE text/css sets the compression to deflate, not gzip, so use filesMatch and set the Content-Encoding header to x-deflate:

<filesMatch "\.(js|css)$">Header set Content-Encoding x-deflate# Header set Content-Encoding compress# Header set Content-Encoding x-gzip</filesMatch>

If that fails, uncomment the compress line and comment the x-deflate line. gzip is not part of the standard Apache installation, so install the gzip module if deflate is not sufficient. As a last resort, create gzipped versions of your CSS and JS files.


I think you're missing AddOutputFilterByType DEFLATE text/javascript. Adding that fixed the issue for me.