Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using mod_deflate to compress my .css and .js files on the fly:

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

The problem is that this compresses the files on the fly, which takes some system resources when dealing with large files.

So I want to pre-compress my files so that they will be served directly to drop down server load. I want to store them with the other css and js files like style.css and style.gz then use php headers to check if the client accepts the gzip encoding to decide whether to serve the .css or the .gz file. FOR THE CHECK IT'S NOT THE PROBLEM. The problem is how to PRE-compress the files.

I came across some topics like this but none of them worked for me. It looks simple but it gave me a 500 Internal Server Error.

Is there any tool or whatever that does this job?

share|improve this question
What is the error in your apache error log? – karmawhore Oct 15 '10 at 3:57

You could write a simple bash script:

for file in *.css *.js; do
  gzip -c $file > $file.gz;
share|improve this answer
+1. It's the logical answer - so logical that I think that we may have misunderstood the question. – lunchmeat317 Jan 18 '12 at 5:04
well, if @user57192 comes back and clarifies, i'll be sure to update my answer. – Jayen Jan 18 '12 at 22:43

Your Answer


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