我正在配置Tomcat以压缩基于文本的文件。目前我的配置如下:
compression="on"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/xml,application/x-javascript,application/json"
然而,我注意到超过60kb的javascript文件没有被压缩。我是否错过了任何隐藏的设置?
在搜索tomcat7文档时,我没有找到关于compressionMaxSize
的参考。唯一类似的命令是compressionMinSize
,它旨在过滤掉小于定义值的任何文件的压缩。就像这样:
compressionMinSize="2048"
以下是我的server.xml文件关于压缩的设置:
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"
事实上,这方面有一些隐藏的文档可以解释您的经验:因此,如果您想通过牺牲CPU利用率来节省带宽,您可以通过将此设置添加到您的web.xml文件中(在这里查看),禁用此触发器。注意:在使用压缩(节省带宽)和使用sendfile功能(节省CPU周期)之间存在折衷。如果连接器支持sendfile功能,例如NIO连接器,则使用sendfile将优先于压缩。症状是大于48 KB的静态文件将以未压缩的形式发送。您可以通过设置连接器的useSendfile属性来关闭sendfile,如下所述进行文档记录,或更改默认servlet中的配置文件conf/web.xml或您的Web应用程序中的web.xml中的sendfile使用阈值。
<init-param>
<param-name>sendfileSize</param-name>
<param-value>96</param-value> <!-- value in KB where compression is turned off in the name of CPU utilization -->
</init-param>