我对所有的SVG文件都使用GZIP。 它在configuration文件(不是.htaccess)
AddType image/svg+xml .svg AddOutputFilterByType DEFLATE image/svg+xml
但是,按F5,浏览器将向服务器请求文件返回200状态码,而不是返回预期的304状态码。
如果我删除了AddOutputFilterByType,那么服务器返回304,但内容不是GZIPped。
这里有一些原始的请求标题
NO GZIP(200状态码)
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状态码)
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
用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
谢谢!
这是Apache中的一个错误,它不能正确处理被压缩内容的Etags。 可以通过closuresgzip(正如你已经注意到的那样 – 但是带来的性能下降)或者closuresETags(并且取决于304s的Last-Modified头部 – 因此没有真正的损失)来解决。 我更喜欢closuresETags。
还有一个替代选项(DeflateAlterETag),但只有在Apache 2.5中,甚至对我来说似乎是一个骗局。
更多细节在这里: 为什么Apache发送200 OK而最后修改匹配If-modified-since?