3

我在我的 tomcat7 server.xml 中使用以下设置启用了压缩:

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" 
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/json,text/javascript,text/css,text/plain,
application/javascript,application/xml,application/xml+xhtml"
/>

我检查了压缩现在使用: http: //www.whatsmyip.org/http-compression-test/

但是,PageSpeed 仍然报告有几个 CSS/JS 文件没有被压缩。例如,压缩http://www.mysite.co.uk/css/bootstrap.css可以节省 109.5KiB(减少 84%)。

4

1 回答 1

2

所有没有压缩的 CSS/JS 文件都比较大吗?也许那些是由“sendfile”发送的,从而避免被压缩。

在文档中:

“注意:使用压缩(节省带宽)和使用 sendfile 功能(节省 CPU 周期)之间存在权衡。如果连接器支持 sendfile 功能,例如 NIO 连接器,则使用 sendfile 将优先于压缩。症状将是大于 48 Kb 的静态文件将在未压缩的情况下发送。您可以通过设置连接器的 useSendfile 属性来关闭 sendfile,如下所述,或者在默认 conf/web 中的 DefaultServlet 的配置中更改 sendfile 使用阈值。 xml 或 web 应用程序的 web.xml 中。”

http://tomcat.apache.org/tomcat-6.0-doc/config/http.html

在您的配置中设置:

useSendfile="false"
于 2013-02-24T22:04:38.960 回答