[英]Gzip working for html, but not javascript or css (Apache)
在我的网站上,html文件已压缩。
但是,javascript,css和svg文件不是。
服务器使用Apache / 2.2.22。
我正在使用HTML5boilerplate中的.htaccess文件。 这是相关的部分:
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE "application/atom+xml" \
"application/javascript" \
"application/json" \
"application/ld+json" \
"application/manifest+json" \
"application/rdf+xml" \
"application/rss+xml" \
"application/schema+json" \
"application/vnd.geo+json" \
"application/vnd.ms-fontobject" \
"application/x-font-ttf" \
"application/x-javascript" \
"application/x-web-app-manifest+json" \
"application/xhtml+xml" \
"application/xml" \
"font/eot" \
"font/opentype" \
"image/bmp" \
"image/svg+xml" \
"image/vnd.microsoft.icon" \
"image/x-icon" \
"text/cache-manifest" \
"text/css" \
"text/html" \
"text/javascript" \
"text/plain" \
"text/vcard" \
"text/vnd.rim.location.xloc" \
"text/vtt" \
"text/x-component" \
"text/x-cross-domain-policy" \
"text/xml"
</IfModule>
就其价值而言-与子文件夹无关。 如果我在主目录中放入一个名为“ test.html”的文件-将其压缩。 如果我将其重命名为“ test.js”,则不是。
[UPDATE]
所以,这真是愚蠢。
如前所述,我使用的是html5boilerplate中的.htaccess文件。
当我仔细观察时,我注意到以下注释:
# (!) For Apache versions below version 2.3.7 you don't need to
# enable `mod_filter` and can remove the `<IfModule mod_filter.c>`
# and `</IfModule>` lines as `AddOutputFilterByType` is still in
# the core directives.
这适用于我,因为服务器使用Apache / 2.2.22。
果然,当我删除<IfModule mod_filter.c>
和<IfModule mod_filter.c>
一切都按它应该有(即的JavaScript,CSS和其他文件类型包括在名单中的所有 gzip压缩。
我会留下这个问题,以防万一其他人犯了与我相同的错误。
您似乎错过了一些东西:
AddType image/svg+xml .svg
AddOutputFilterByType DEFLATE image/svg+xml
https://stackoverflow.com/a/21533084/1491007
最好,拉尔夫
所以,这真是愚蠢。
如前所述,我使用的是html5boilerplate中的.htaccess文件。
当我仔细观察时,我注意到以下注释:
# (!) For Apache versions below version 2.3.7 you don't need to
# enable `mod_filter` and can remove the `<IfModule mod_filter.c>`
# and `</IfModule>` lines as `AddOutputFilterByType` is still in
# the core directives.
这适用于我,因为服务器使用Apache / 2.2.22。
果然,当我删除<IfModule mod_filter.c>
和<IfModule mod_filter.c>
一切都按它应该有(即的JavaScript,CSS和其他文件类型包括在名单中的所有 gzip压缩。
我会留下这个答案,以防万一其他人犯了与我相同的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.