views:

2033

answers:

3

I'm using Apache.

I'm auto gzipping my HTML & CSS files on the fly using the following directive in my .htaccess file.

# Enable ETag
FileETag MTime Size


# Set expiration header
ExpiresActive on
ExpiresDefault "access plus 1 year"
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
ExpiresByType text/js A2592000


# Compress some text file types
AddOutputFilterByType DEFLATE text/html text/css text/xml application/x-javascript text/javascript text/js


# Deactivate compression for buggy browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

However, when I use the Firebug plugin for Firefox, I notice that my javascript files are NOT being gzipped (only my HTML and CSS files are).

Any ideas why my JavaScript files are not being gzipped on the fly by Apache?

+2  A: 

Have you declared the text/javascript MIME type in Apache? If your server configuration points to, say, a mime.types file with one of these:

TypesConfig /private/etc/apache2/mime.types

then said file should include this line:

application/javascript     js

Otherwise, you should see one of these somewhere:

AddType application/javascript .js

At least, this is my first guess, if HTML and CSS files are being compressed and JavaScript files aren't.

Jim Puls
+3  A: 

I figured it out, looks like I need it to be:

AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/x-javascript text/javascript application/javascript

To get javascript to compress/gzip

using this, I still have the same problem. Javascript and Css files are not compressed.
Morteza M.
Doesn't work for me either.
gnucom
A: 

hi, I am new into that, but each time I try to add your lines in my htaccess file, then I get an Internal Server Error for the whole site, any idea? thanks Eric

eric
Do you have DEFLATE/gzip enabled on your server?
Dennis
See in your server's error log to find out what is the error.
Morteza M.
if you use apache, then you need to enable mod_expire and mod_deflate.
Morteza M.