【发布时间】:2011-09-10 22:35:34
【问题描述】:
我想 Gzip 数据(css,js)在 php 中发送到浏览器。我尝试了gzcompress、gzencode,但都使文件无法被浏览器识别
来自 firebug 的 home.css 数据
Date Sat, 10 Sep 2011 22:31:59 GMT
Server Apache/2.2.14 (Ubuntu)
X-Powered-By PHP/5.3.2-1ubuntu4.9
Expires Sat, 17 Sep 2011 22:31:59 GMT
Cache-Control public
Pragma no-cache
Etag e35b61f80bbf8e0dd722c50c65ec6da5
Vary Accept-Encoding
Content-Encoding gzip
Content-Length 25163
Keep-Alive timeout=15, max=92
Connection Keep-Alive
Content-Type text/css
编辑:我什至在下面尝试过也没有用
<?php
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
ob_start("ob_gzhandler");
else
ob_start();
?>
【问题讨论】:
-
您使用的代码可能很有帮助,可能是标题有问题
-
ob_gzhandler已经检查了 Accept-Encoding 标头以确定应如何对输出进行编码,您无需自己执行此操作。 -
您发布的标头基本上看起来是正确的(它们包括正确的 Content-Encoding 和 Vary 标头)。您的输出可能已经在 Apache 级别进行了压缩,因此您也在 PHP 中进行双重编码。
标签: php apache http http-headers