Tomcat 6上的Gzip压缩

问题描述 投票:0回答:4

有什么区别

压缩=“上”

压缩=“力”

?

Tomcat documentation说:

“on” - 允许压缩,这会导致文本数据被压缩

“武力” - 在所有情况下强制压缩

有什么额外的案例?

而且,更重要的是,建议哪种价值适用于生产环境?

tomcat compression gzip tomcat6
4个回答
0
投票

压缩与否,是在negotiation between the server and client期间决定的。

强制压缩意味着服务器将发送压缩内容,无论客户端是否支持它。


0
投票

我无法100%确定有什么区别(我正在寻找相同的信息)但我可以肯定地说,当客户端没有发送相关的Accept-Encoding标头时,“force”值不会压缩,根据我刚刚执行的测试(使用tomcat 8.0.8)。此外,它没有多大意义,打破了这么多的http客户端。

我想“on”和“force”之间的区别在于其他压缩参数。例如。 “on”将使用compressableMimeType和noCompressionUserAgents,而“force”将压缩忽略这两个参数(例如,对于所有mime类型和所有用户代理)。


0
投票

实际上,如果客户端支持压缩,“强制”只是强制。

注意力是在“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;
    }
    ...

Source


0
投票

我认为这是由于使用中检查压缩...

    /**
 * 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;
    }
© www.soinside.com 2019 - 2024. All rights reserved.