加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 00:03:19 所属栏目:Java 来源:网络整理
导读:我正在配置tomcat来压缩基于文本的文件. 我目前的配置有: compression="on"compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/xml,application/x-javascript,application/json" 但是,我注意到~60kb以上的javascri
我正在配置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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读