How can I gzip my JavaScript and CSS files? How can I gzip my JavaScript and CSS files? apache apache

How can I gzip my JavaScript and CSS files?


You can use apache's mod_deflate to automatically compress your files on the fly.

Example:

AddOutputFilterByType DEFLATE text/html text/xml text/css text/javascript 

[edit]

To check if your apache server has already output compression enabled, put the example above into an .htaccess file. Then load an html or js file via the server and check the headers for "Content-Encoding", if it says gzip or deflate, it is enabled.


add this code to your .htaccess it will gzip all your css and js files.

# BEGIN GZIP<ifmodule mod_deflate.c>AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript</ifmodule># END GZIP


I above example similar to this worked great but didn't compress javascript. I needed to add application/javascript.

AddOutputFilterByType DEFLATE text/html text/xml text/css text/javascript application/javascript