.htaccess - 如何仅压缩 Apache 提供的 150 字节以上的文档?

标签 .htaccess compression gzip

Google 告诉我们 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 字节以上的文件?

谢谢。

最佳答案

我认为尝试这个不会有任何收获。这些小文件的压缩和解压缩速度非常快,即使在移动设备上也是如此。此外,150 字节远低于互联网上的正常 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 字节,因此您的设置已经达到了您想要的效果。

关于.htaccess - 如何仅压缩 Apache 提供的 150 字节以上的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9871798/

相关文章:

java - ZipInputStream.getNextEntry 在某些 zip 文件上返回 null

jquery - 与 jQuery grunt 脚本相比,Jammit 对 jQuery 1.9.1 的压缩效果很差(145k vs 93k)

javascript - 在 rails 中,如何 g-zip 由 'javascript_include_tag' 生成的组合 javascript 文件?

java - .NET 中 Java Gzip 解压错误

javascript - 使用 pako.js 在 javascript 中对字符串进行 Gzip 压缩

ruby-on-rails - Rails 应用程序显示文件而不是显示应用程序

php - 使用虚拟主机时如何设置apache的环境变量?

apache - 使用 .htaccess 将一个 url 重定向到另一个 url

php - 图片加载失败,net::ERR_CONTENT_LENGTH_MISMATCH

c# - C# 中的 GIF LZW 压缩