0

我目前像这样启用 GZIP:

# gzip compression
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript application/json
</ifmodule>

这会产生如下响应标头:

在此处输入图像描述

请注意,Content-Encoding设置为gzip,并且Vary也设置了。

现在,我想使用这个 .htaccess 文件中的代码,据说可以提高性能,但是当我用这个替换上面的代码时:

# --------------------------------------------------------------------------------------
# Compression: http://code.google.com/speed/page-speed/docs/payload.html#GzipCompression
# --------------------------------------------------------------------------------------
<IfModule mod_deflate.c>
AddOutputFilter DEFLATE application/atom+xml
AddOutputFilter DEFLATE application/json
AddOutputFilter DEFLATE application/xhtml+xml
AddOutputFilter DEFLATE application/xml
AddOutputFilter DEFLATE text/css
AddOutputFilter DEFLATE text/html
AddOutputFilter DEFLATE text/plain
AddOutputFilter DEFLATE text/x-component
AddOutputFilter DEFLATE text/xml

# The following MIME types are in the process of registration
AddOutputFilter DEFLATE application/xslt+xml
AddOutputFilter DEFLATE image/svg+xml

# The following MIME types are NOT registered
AddOutputFilter DEFLATE application/mathml+xml
AddOutputFilter DEFLATE application/rss+xml

# JavaScript has various MIME types
AddOutputFilter DEFLATE application/javascript
AddOutputFilter DEFLATE application/x-javascript
AddOutputFilter DEFLATE text/ecmascript
AddOutputFilter DEFLATE text/javascript

# .ico files and other compressible images
AddOutputFilter DEFLATE image/vnd.microsoft.icon
AddOutputFilter DEFLATE image/x-icon
AddOutputFilter DEFLATE image/bmp
AddOutputFilter DEFLATE image/tiff
AddOutputFilter DEFLATE application/pdf

# compressible fonts (.woff is already compressed)
AddOutputFilter DEFLATE font/opentype
AddOutputFilter DEFLATE application/x-font-ttf
AddOutputFilter DEFLATE application/vnd.ms-fontobject
</IfModule>

同一文件请求的响应标头变为:

在此处输入图像描述

Content-Encoding: gzip头不再存在。此外,Transfer-EncodingVary也消失了,现在。

这里发生了什么?为什么这个新代码无法 gzip 文件?

4

1 回答 1

1

AddOutputFilterByType接受媒体类型,在这种情况下是:

application/json

AddOutputFilter接受文件扩展名,在这种情况下是:

json

参考

于 2015-05-26T02:46:27.790 回答