2015-12-04 28 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和其他文件类型如果其他人犯了同样的错误,我也会这么做。

相关问题