Apache deflate javascript 压缩率 1.00x
Apache deflate javascript compress ratio 1.00x
如果我在 CLI 中 运行 gzip,我可以获得很好的压缩率:
bundle.js: 75.3% -- replaced with bundle.js.gz
但在 Apache 中,即使我设置了 deflate,它也会压缩,但文件大小相同。下面是我的 Apache 配置:
LoadModule deflate_module libexec/apache2/mod_deflate.so
<IfModule deflate_module>
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE application/javascript text/plain text/css
CustomLog /var/log/deflate_log DEFLATE
</IfModule>
以下是回复:
ETag "8342b-53dc33d01d2c0-gzip"
Server Apache/2.4.23 (Unix)
Content-Type application/javascript
Last-Modified Sat, 01 Oct 2016 01:00:35 GMT
Date Sun, 02 Oct 2016 01:14:20 GMT
Connection Keep-Alive
Vary Accept-Encoding
Accept-Ranges bytes
Keep-Alive timeout=5, max=98
Content-Encoding gzip
Transfer-Encoding Identity
网络t运行sfer size与之前相同,比例为1.00x。我将它缩小到只有 js 不被压缩,而不是 css 获得 6.22x 的良好压缩比。是不是js文件有问题?
我明白了!
我注意到回复中没有 "content-length" header。所以我回去查看Apache文档。它说:
The DeflateBufferSize directive specifies the size in bytes of the
fragments that zlib should compress at one time. If the compressed
response size is bigger than the one specified by this directive then
httpd will switch to chunked encoding (HTTP header Transfer-Encoding
set to Chunked), with the side effect of not setting any
Content-Length HTTP header. This is particularly important when httpd
works behind reverse caching proxies or when httpd is configured with
mod_cache and mod_cache_disk because HTTP responses without any
Content-Length header might not be cached.
由于我的js文件是500k,远远超过默认的8k设置,所以我在conf文件中添加了以下内容,现在一切正常:
<IfModule deflate_module>
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE application/javascript text/plain text/css
DeflateBufferSize 8096000
</IfModule>
如果我在 CLI 中 运行 gzip,我可以获得很好的压缩率:
bundle.js: 75.3% -- replaced with bundle.js.gz
但在 Apache 中,即使我设置了 deflate,它也会压缩,但文件大小相同。下面是我的 Apache 配置:
LoadModule deflate_module libexec/apache2/mod_deflate.so
<IfModule deflate_module>
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE application/javascript text/plain text/css
CustomLog /var/log/deflate_log DEFLATE
</IfModule>
以下是回复:
ETag "8342b-53dc33d01d2c0-gzip"
Server Apache/2.4.23 (Unix)
Content-Type application/javascript
Last-Modified Sat, 01 Oct 2016 01:00:35 GMT
Date Sun, 02 Oct 2016 01:14:20 GMT
Connection Keep-Alive
Vary Accept-Encoding
Accept-Ranges bytes
Keep-Alive timeout=5, max=98
Content-Encoding gzip
Transfer-Encoding Identity
网络t运行sfer size与之前相同,比例为1.00x。我将它缩小到只有 js 不被压缩,而不是 css 获得 6.22x 的良好压缩比。是不是js文件有问题?
我明白了!
我注意到回复中没有 "content-length" header。所以我回去查看Apache文档。它说:
The DeflateBufferSize directive specifies the size in bytes of the fragments that zlib should compress at one time. If the compressed response size is bigger than the one specified by this directive then httpd will switch to chunked encoding (HTTP header Transfer-Encoding set to Chunked), with the side effect of not setting any Content-Length HTTP header. This is particularly important when httpd works behind reverse caching proxies or when httpd is configured with mod_cache and mod_cache_disk because HTTP responses without any Content-Length header might not be cached.
由于我的js文件是500k,远远超过默认的8k设置,所以我在conf文件中添加了以下内容,现在一切正常:
<IfModule deflate_module>
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE application/javascript text/plain text/css
DeflateBufferSize 8096000
</IfModule>