我正在配置tomcat来压缩基于文本的文件.我目前的配置有:
compression="on"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/xml,application/x-javascript,application/json"
Run Code Online (Sandbox Code Playgroud)
但是,我注意到~60kb以上的javascript文件没有被压缩.我错过了任何隐藏的设置吗?
Jas*_*ske 12
搜索tomcat7的文档我找不到对a的引用compressionMaxSize.像这样的唯一命令是compressionMinSize过滤掉任何小于定义值的文件的压缩.像这样:
compressionMinSize="2048"
Run Code Online (Sandbox Code Playgroud)
这是我的server.xml在压缩方面的样子:
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml"
Run Code Online (Sandbox Code Playgroud)
实际上有一些与此相关的文档可以解释您的经验:
注意:在使用压缩(节省带宽)和使用sendfile功能(节省CPU周期)之间需要权衡.如果连接器支持sendfile功能,例如NIO连接器,则使用sendfile将优先于压缩.症状将是静态文件大于48 Kb将被解压缩.您可以通过设置连接器的useSendfile属性来关闭sendfile,如下所述,或者更改默认conf/web.xml或Web应用程序的web.xml中DefaultServlet配置中的sendfile使用率阈值.
因此,如果您想以牺牲CPU利用率为代价来节省带宽,可以通过将此设置添加到web.xml来禁用此触发器(如此处所示):
<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>
Run Code Online (Sandbox Code Playgroud)