Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

the following configuration in httpd.conf only gzip css and html, not javascript, any idea?

AddOutputFilterByType DEFLATE text/html text/plain text/javascript text/css
AddOutputFilterByType DEFLATE application/x-javascript
share|improve this question

2 Answers 2

up vote 4 down vote accepted

That's most likely because the MIME type for Javascript is hotly contested.

Try adding application/javascript and text/x-js (as well as application/x-javascript)

That said, a more reliable way may be to filter based on the .js file extension. See the Request_URI directive for more info (http://httpd.apache.org/docs/2.0/mod/mod_deflate.html) - this may not work if you're using rewritten URLs that do not use the .js extension for JavaScript files.

If this doesn't work, then your distro of Linux may be using a completely different MIME type for JavaScript. Locate the TypesConfig directive in your config file, and have a look to see how it's defining JavaScript. Then add that MIME type in as well.

share|improve this answer

This is probably your best approach:

<IfModule mod_deflate.c>
      AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
      BrowserMatch ^Mozilla/4 gzip-only-text/html
      BrowserMatch ^Mozilla/4\.[0678] no-gzip
      BrowserMatch \bMSIE\s(7|8)  !no-gzip !gzip-only-text/html
      Header set Vary *
      DeflateCompressionLevel 1

Internet Explorer (certain versions) does not play well with hectic compression, so it's best to approach compression on a browser by browser basis. These settings are from a high volume website with lots of clients - and were the only settings we tried that worked 100% of the time.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.