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.

I have a server serving up a JS file a few million times a day using apache2. Some of my users would like the JS to be gzipped. Does anyone know how apache2 mod_deflate handles compression of static files? Will it compress the js for each request(in which case I'd be worried about cpu load)? If it does, is there a way to pre-compress the JS files so apache2 wouldn't have to do this for each file?

share|improve this question
2  
See this post on Stack Overflow: stackoverflow.com/questions/75482/… –  Phil Ross Apr 11 '10 at 22:20
    
sweet1! thanks! –  rizen Apr 11 '10 at 22:32
    
mod_deflate will keep compressed files in memory the best it can. Obviously memory constraints play into which files will be cached and for how long. If you want to ensure certain files are cached all the time see the Multiviews instructions below. –  Chris S Jan 23 '12 at 21:44

1 Answer 1

You can do it with

Options +Multiviews

then precompress the file as whatever.js.gz using

gzip -c -9 whatever.js > whatever.js.gz

However, if there are older browsers that may break with this.

In the apache config

AddEncoding x-gzip .gz

Remove

AddType application/x-gzip .gz
share|improve this answer

Your Answer

 
discard

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