Adding compression to Apache

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Adding compression to Apache

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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
Last edited by Weirdan on Sun Jun 17, 2007 3:44 pm, edited 1 time in total.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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)
Post Reply