java – 如何设置最大tomcat gzip压缩大小?

前端之家收集整理的这篇文章主要介绍了java – 如何设置最大tomcat gzip压缩大小?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在配置tomcat来压缩基于文本的文件.
我目前的配置有:
compression="on"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/xml,application/x-javascript,application/json"

但是,我注意到~60kb以上的javascript文件没有被压缩.
我错过了任何隐藏的设置吗?

解决方法

搜索 documentation for tomcat7我找不到对compressionMaxSize的引用.像这样的唯一命令是compressionMinSize,它旨在过滤掉任何小于定义值的文件的压缩.像这样:
compressionMinSize="2048"

这是我的server.xml在压缩方面的样子:

compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla,traviata"
compressableMimeType="text/html,text/xml"

实际上有一些与此相关的文档可以解释您的经验:

Note: There is a tradeoff between using compression (saving your
bandwidth) and using the sendfile feature (saving your cpu cycles). If
the connector supports the sendfile feature,e.g. the NIO connector,
using sendfile will take precedence over compression. The symptoms
will be that static files greater that 48 Kb will be sent
uncompressed.
You can turn off sendfile by setting useSendfile
attribute of the connector,as documented below,or change the
sendfile usage threshold in the configuration of the DefaultServlet in
the default conf/web.xml or in the web.xml of your web application.

因此,如果您想以牺牲cpu利用率为代价来节省带宽,可以通过将此设置添加到web.xml(seen here)来禁用此触发器:

<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>
原文链接:https://www.f2er.com/java/126822.html

猜你在找的Java相关文章