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 apache 2.2.11 installed on my server and I have been trying to decrease the load time of my website pages based on the advice from the yslow firefox plugin.

I have configured gzip and etag and some of its other suggestions fine but I have noticed in the header for my css files etag is being appended with the text gzip.

Does anyone know why and how to get round this?

Header from my server
Date    Sun, 07 Jun 2009 10:40:57 GMT
Server  Apache/2.2.11 (Fedora)
Last-Modified   Sun, 31 May 2009 15:06:38 GMT
Etag    "3b4-46b36a802bb80"-gzip
Accept-Ranges   bytes
Cache-Control   max-age=2592000
Expires Tue, 07 Jul 2009 10:40:57 GMT
Vary    Accept-Encoding
Content-Encoding    gzip
Content-Length  530
Connection  close
Content-Type    text/css
The same code on my hosted package uses an older version of apache and doesn't have the same problem. Could this just be an apache bug?
Header from my hosting package
Date    Sun, 07 Jun 2009 10:48:26 GMT
Server  Apache/2.0.63 (FreeBSD) mod_python/3.3.1 Python/2.5.1 PHP/5.2.6 with Suhosin-Patch mod_fastcgi/2.4.6 mod_ssl/2.0.63 OpenSSL/0.9.7e-p1 DAV/2 mod_perl/2.0.4 Perl/v5.8.8
Last-Modified   Sat, 21 Feb 2009 13:54:52 GMT
Etag    "3b4-1d104300"
Accept-Ranges   bytes
Cache-Control   max-age=2592000
Expires Tue, 07 Jul 2009 10:48:26 GMT
Vary    Accept-Encoding
Content-Encoding    gzip
Content-Length  530
Connection  close
Content-Type    text/css
share|improve this question
    
What exactly is bad about that "-gzip" append? Since clients will always request either the gzipped or non-gzipped version, they won't end up having to cache two copies. Intermediate proxies will possibly now see two different files, but that's good, as if they only stored one of the variants, some people might receive the wrong format. –  Alex Jurkiewicz Jun 7 '09 at 12:43
    
The "-gzip" append is bad because it violates RFC 2616. ETags should not have suffixes outside the " symbol. So ETag: "foo" is good (and valid) but ETag: "foo"-gzip is not. A correctly formatted gzip suffix would be ETag: "foo-gzip" –  mogsie Feb 6 at 23:19

2 Answers 2

up vote 4 down vote accepted

Here's an ideal .htaccess that both compresses and sets sutiable expire headers.

# 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

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

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
  ExpiresByType text/html "access plus 600 seconds"
  ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </FilesMatch>
  <FilesMatch "\\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </FilesMatch>
  <FilesMatch "\\.(js)$">
    Header set Cache-Control "max-age=216000, private"
  </FilesMatch>
  <FilesMatch "\\.(x?html?|php)$">
    Header set Cache-Control "max-age=600, private, must-revalidate"
  </FilesMatch>
</IfModule>

<IfModule mod_headers.c>
  Header unset ETag
</IfModule>
FileETag None

<IfModule mod_headers.c>
  Header unset Last-Modified
</IfModule>

The following article covers what it does and also talks about compression:

http://www.samaxes.com/2009/01/06/more-on-compressing-and-caching-your-site-with-htaccess/

Hope that helps.

share|improve this answer
    
As a note, this removes the etags. This is because for instance if you are serving you site from several servers, the etags can vary with each machine, it is better to just use cache control & expires. –  Sam Jun 7 '09 at 13:16

Can you elaborate on how you configured gzip? For example, are you using mod_deflate? Can you post snippets from your httpd.conf, especially the AddOutputFilterByType field? I followed these directions for my particular hosting provider, and it's possible that text/css isn't in the list at your hosting provider:

http://kb.mediatemple.net/questions/1567/Compressing+web+pages+with+mod_deflate

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.