【问题标题】:How to ONLY compress documents above 150 bytes served by Apache?如何仅压缩 Apache 提供的 150 字节以上的文档?
【发布时间】:2012-03-26 12:07:29
【问题描述】:

谷歌告诉我们here,那:

"...gzipping 只对较大的资源有益。由于压缩和解压缩的开销和延迟,您应该只 gzip 超过一定大小阈值的文件;我们建议最小范围在 150 到 1000 字节之间。gzipping 文件低于 150 字节实际上可以使它们变大。”

我现在使用

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

在我的 .htaccess 中。我怎样才能使它仅适用于 150 字节以上的文件?

谢谢。

【问题讨论】:

    标签: .htaccess compression gzip


    【解决方案1】:

    我认为尝试这个不会有任何收获。这些小文件的压缩和解压速度非常快,即使在移动设备上也是如此。此外,150 字节远低于 Internet 上的正常 MTU,因此即使压缩增加了它的大小,它仍然只是一个 IP 数据包。

    但由于您使用的是 mod_gzip 而不是 mod_deflate,您可以使用以下内容。

    # minimum size (in bytes) for files to be compressed
      mod_gzip_minimum_file_size    500
    # (for very small files compression will produce only small absolute gains
    #  [you will still save about 50% of the content, but some additional
    #  500 bytes of HTTP and TCP headers will always remain uncompressed],
    #  but still produce CPU load for both client and server.
    #  mod_gzip will automatically set smaller values than 300 bytes for
    #  this directive to exactly this value 300.)
    

    请注意,默认值为 300 字节,因此您的设置已经在执行您想要的操作。

    【讨论】:

    • 谢谢格本。实际上,在我发布这个之后,当我开始考虑 150 字节时,我已经在路上了,我突然想到这是一个非常小的文件大小,除了 robots.txt 之外可能没有其他文件。这反过来让我相信,谷歌在他们的文章中甚至提到它是没有意义的,反过来也使这个问题变得无稽之谈!
    • 感谢代码行,如果我想做一些依赖文件大小的事情,很高兴知道语法。关于检查。我检查了我所知道的:gzip 正在工作,并且根据“Page Speed”和“Yslow”产生了很大的不同。
    【解决方案2】:

    有意义的压缩阈值 150 取决于内容。具有高度随机内容的文件不能很好地压缩,如果有的话。即使文件大小大于 150 或更多。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-30
      • 1970-01-01
      • 2014-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多