2015-12-04 25 views
1

在我的網站上,html文件是gzip。Gzip適用於html,但不適用於JavaScript或css(Apache)

但是,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」 - 事實並非如此。

[更新]

所以,這是愚蠢的。

正如我所提到的,我使用的是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>,一切都按它應該有(即包含在該列表中所有 gzip壓縮。

我的JavaScript,CSS和其他文件類型會離開這個問題,以防萬一別人讓我做了同樣的錯誤

+1

檢查你的配置的其餘部分是否爲「gzip-only-text/html」? 或其他SetOutputFilter? 或者這個.htaccess不是閱讀和defalte設置在其他地方? – covener

回答

1

所以,這是愚蠢的。

正如我所提到的,我使用的是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>,一切都按它應該有(即包含在該列表中所有 gzip壓縮。

我的JavaScript,CSS和其他文件類型如果其他人犯了同樣的錯誤,我也會這麼做。

相關問題