Page 1 of 1

Adding compression to Apache

Posted: Sun Jun 17, 2007 3:14 pm
by Ambush Commander
I'd like add compression to my website. However, after doing some preliminary research, I have come out being more confused than when I started.

I have a specific set of requirements:

1. The method must work with Apache 2. This rules out mod_gzip for my shared servers setup.

2. The server must not compress the file each time it is requested. This is extremely wasteful and most of my content is static. It appears mod_gzip has the ability to do this, but due to requirement one I cannot do use it. mod_deflate does not appear to be able to do this (and its compression level is specifically set lower by default to compensate)

3. The compression must be done in a cross-browser compatible way to ensure minimal breakage if a browser is known not to handle gzipped content correctly. It appears this document would be helpful in implementing this. Also, a previous forum member has posted on this topic and mentioned a specific set of mod_rewrite rules that are a very practical implementation of the rules.

From these three requirements, it looks like I will have to forgo any compression module and hand-compress the files myself, in a manner similar to Arawn's solution. I'd like to field the question to you guys, however, if there is a better way (i.e. needs less work) of achieving the same functionality?

Posted: Sun Jun 17, 2007 3:42 pm
by Weirdan
with mod_rewrite you could test if compressed content available and, if not, redirect request to some php script that would both send compressed content to the client and store compressed version, so subsequent requests would forego php completely.

I believe something like this is used in Symfony framework where they cache html output to .html files

Posted: Sun Jun 17, 2007 3:43 pm
by Ambush Commander
Agreed. In fact, my system's current implementation makes this extremely easy to do. I'm a bit wary about using mod_rewrite for everything, though: it's not exactly the fastest. (I'll probably end up using it anyway)