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/