GZIP压缩在htaccess中似乎不起作用

时间:2014-06-04 15:24:28

标签: css performance apache .htaccess gzip

我正试图改善网站的性能,但无论我尝试什么,我都会在“启用gzip压缩”上获得低分(21%)。其他所有东西都在高达90分到100分。这真的让我烦恼,因为它似乎适用于某些网站,而不是其他网站。

我的.htaccess中的代码如下。 #BEGIN GZIP到#END GZIP是我在css tricks评论时尝试的新内容,但它看起来适用于旧版本的apache。如何通过.htaccess文件增加“启用gzip压缩”的分数?

FileETag MTime Size

# BEGIN GZIP
# mod_gzip compression (legacy, Apache 1.3)
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|xml|txt|css|js)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
# END GZIP

# DEFLATE compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|ico)$">
Header set Cache-Control "public"
Header set Expires "Thurs, 06 Jan 2016 14:30:00 GMT"
Header set Last-Modified "Thurs, 06 Jan 2014 14:30:00 GMT"
</FilesMatch>

<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>

0 个答案:

没有答案