0
  • OS: Ubuntu 14.04
  • Apache: 2.4.12 (using PPA) - mod_expires, mod_headers

I am using GZIP for all SVG files. It works well with the following statement in a configuration file (not .htaccess)

AddType image/svg+xml .svg
AddOutputFilterByType DEFLATE image/svg+xml

However, hitting F5, the browser will request the file to the server returning a 200 Status Code instead of returning the expected 304 Status Code.

If I remove AddOutputFilterByType then the server returns 304 but the content is not GZIPped.

Here are some raw request headers

NO GZIP (200 Status Code)

Accept-Ranges: bytes
Cache-Control: max-age=2592000
Connection: Keep-Alive
Content-Length: 689
Content-Type: image/svg+xml
Date: Thu, 02 Jul 2015 10:41:09 GMT
Etag: "2b1-5157f331b2480"
Expires: Sat, 01 Aug 2015 10:41:09 GMT
Keep-Alive: timeout=5, max=80
Last-Modified: Thu, 07 May 2015 15:02:26 GMT
Server: Apache

NO GZIP (304 Status Code)

Cache-Control: max-age=2592000
Connection: Keep-Alive
Date: Thu, 02 Jul 2015 10:39:12 GMT
Etag: "2b1-5157f331b2480"
Expires: Sat, 01 Aug 2015 10:39:12 GMT
Keep-Alive: timeout=5, max=71
Server: Apache

With GZIP

Accept-Ranges: bytes
Cache-Control: max-age=2592000
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 451
Content-Type: image/svg+xml
Date: Thu, 02 Jul 2015 10:38:45 GMT
Etag: "2b1-5157f331b2480-gzip"
Expires: Sat, 01 Aug 2015 10:38:45 GMT
Keep-Alive: timeout=5, max=75
Last-Modified: Thu, 07 May 2015 15:02:26 GMT
Server: Apache
Vary: Accept-Encoding

Thank you!

1 Answers1

2

It's a bug in Apache where it doesn't handle Etags properly for gzipped contents. Can be resolved by either turning off gzip (as you have noticed - but with the performance hit that entails) or turning off ETags (and depending on Last-Modified header for 304s - so no real loss). I prefer to turn off ETags.

There is also an alternative option (DeflateAlterETag) but only in Apache 2.5 and even that seems like a fudge to me.

More details here: Why does Apache send 200 OK while Last-modified matches If-modified-since?

Barry Pollard
  • 4,461
  • 14
  • 26