【发布时间】:2015-04-10 07:53:41
【问题描述】:
有什么区别
压缩=“开”
和
压缩=“力”
?
"on" - 允许压缩,这会导致文本数据被压缩
"force" - 在所有情况
中强制压缩
额外的情况是什么?
还有什么更重要的是,推荐用于生产环境的值是什么?
【问题讨论】:
标签: tomcat compression gzip tomcat6
有什么区别
压缩=“开”
和
压缩=“力”
?
"on" - 允许压缩,这会导致文本数据被压缩
"force" - 在所有情况
中强制压缩
额外的情况是什么?
还有什么更重要的是,推荐用于生产环境的值是什么?
【问题讨论】:
标签: tomcat compression gzip tomcat6
压缩与否,由negotiation between the server and client决定。
强制压缩意味着无论客户端是否支持,服务器都会发送压缩内容。
【讨论】:
我不能 100% 确定有什么区别(我正在寻找相同的信息),但我可以肯定地说,当客户没有发送相关的接受时,“强制”值不会压缩-编码头,根据我刚刚执行的测试(使用tomcat 8.0.8)。此外,它没有什么意义,会破坏这么多 http 客户端。
我想“on”和“force”之间的区别在于其他压缩参数。例如。 “on”将使用 compressableMimeType 和 noCompressionUserAgents,而“force”将忽略这两个参数进行压缩(例如,对于所有 mime 类型和所有用户代理)。
【讨论】:
实际上“强制”只是强制如果客户端支持压缩。
注意强制是“Content-Encoding”标头检查...
/**
* Check if the resource could be compressed, if the client supports it.
*/
private boolean isCompressible() {
// Check if content is not already compressed
MessageBytes contentEncodingMB = response.getMimeHeaders().getValue("Content-Encoding");
if ((contentEncodingMB != null) &&
(contentEncodingMB.indexOf("gzip") != -1 ||
contentEncodingMB.indexOf("br") != -1)) {
return false;
}
// If force mode, always compress (test purposes only)
if (compressionLevel == 2) {
return true;
}
...
【讨论】:
我认为这是由于签入 useCompression ...
/**
* Check if compression should be used for this resource. Already checked
* that the resource could be compressed if the client supports it.
*/
private boolean useCompression() {
// Check if browser support gzip encoding
MessageBytes acceptEncodingMB =
request.getMimeHeaders().getValue("accept-encoding");
if ((acceptEncodingMB == null)
|| (acceptEncodingMB.indexOf("gzip") == -1)) {
return false;
}
// If force mode, always compress (test purposes only)
if (compressionLevel == 2) {
return true;
}
【讨论】: