我创建了一个页面,该页面将采用 css(或 javascript)文件并将它们作为一个文件输出。我注意到,当我使用以下命令压缩输出时,Firefox 和 Internet Explorer 在任何时候都无法发送“If-Modified-Since”标头ob_gzhandler
:
if(!ob_start("ob_gzhandler")) ob_start();
初始标头(示例中更改了主机和引用者):
Response Headers
Cache-Control public, must-revalidate, maxage=4838400
Connection keep-alive
Content-Encoding gzip
Content-Length 87281
Content-Type text/css; charset: UTF-8
Date Wed, 12 Dec 2012 16:04:32 GMT
Expires Wed, 06 Feb 2013 16:04:32 GMT
Last-Modified Fri, 12 Oct 2012 13:47:18 GMT
Pragma public
Server Apache
Vary Accept-Encoding
X-Cache MISS from localhost
X-Powered-By PHP/5.3.13
Request Headers
Accept text/css,*/*;q=0.1
Accept-Encoding gzip, deflate
Accept-Language en-gb,en;q=0.5
Authorization Basic cmVkZnVzZTpyM2RmdXMz
Cache-Control no-cache
Connection keep-alive
Cookie PHPSESSID=e73355c49f06a059c22d7f02687dc51b
DNT 1
Host example.com
Pragma no-cache
Referer http://example.com/
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0
刷新时发送以下标头(示例中更改了主机和引荐来源网址):
Response Headers
Cache-Control public, must-revalidate, maxage=4838400
Connection keep-alive
Content-Encoding gzip
Content-Length 87245
Content-Type text/css; charset: UTF-8
Date Wed, 12 Dec 2012 16:09:11 GMT
Expires Wed, 06 Feb 2013 16:09:11 GMT
Last-Modified Fri, 12 Oct 2012 13:47:18 GMT
Pragma public
Server Apache
Vary Accept-Encoding
X-Cache MISS from localhost
X-Powered-By PHP/5.3.13
Request Headers
Accept text/css,*/*;q=0.1
Accept-Encoding gzip, deflate
Accept-Language en-gb,en;q=0.5
Authorization Basic cmVkZnVzZTpyM2RmdXMz
Cache-Control max-age=0
Connection keep-alive
Cookie PHPSESSID=e73355c49f06a059c22d7f02687dc51b
DNT 1
Host example.com
Referer example.com
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0
如果我从使用切换ob_gzhandler
到标准ob_start()
,那么它可以正常工作并在第二次加载时按预期返回 304。
我认为相关的另一个问题是,从 android 设备查看时,css 既不适用于股票浏览器,也不适用于 Dolphin 浏览器,但适用于 Firefox for Android。这也可以通过禁用ob_gzhandler