2

We have a Apache 2.2 with mod_cache and mod_deflate among other modules. The problem is that if we append Vary header as in Apache documentation...

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

... we end up having copy of the served resource for each user agent variation in our cache. This wastes disk space and lowers the hit rate.

So, what is the preferred solution for this problem? Ditch the Vary header and compress only "safe" resources like plain html?

Petteri H
  • 227
  • 5
  • 12

1 Answers1

7

The reason for setting the header to vary by user agent is that Apache's recommended configuration for mod_deflate serves uncompressed versions of some content to Netscape 4 users. There are probably few enough Netscape 4 users now that you can just serve compressed content to all browsers that claim to support it, and not vary by user agent.

So instead of the recommended configuration:

<Location />
# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>

You can just have:

<Location />
# Insert filter
SetOutputFilter DEFLATE

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
</Location>
Mike Scott
  • 7,903
  • 29
  • 26
  • 1
    Netscape 4.0x was released in 1998, and even Microsoft celebrated the death of IE6. I agree it's time we move on :) – Hank Feb 28 '12 at 20:42