簡體   English   中英

Gzip適用於html,但不適用於javascript或css(Apache)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM