Gzip已融为一体pression通过的.htaccess不工作 [英] Gzip compression through .htaccess not working

查看:271
本文介绍了Gzip已融为一体pression通过的.htaccess不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在建立一个网站,并检查它的运行速度通过 gtmetrix.com 。我用下面的的.htaccess 文件到COM preSS的的.js,的CSS 和许多文件。

I have been creating a site and checking it's speed through gtmetrix.com. I used the following .htaccess file to compress the .js, .css and many more files.

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  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>

ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php

Options Indexes
IndexOptions FancyIndexing

ExpiresActive On
ExpiresDefault "access plus 7 days"
ExpiresByType application/javascript A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/javascript A2592000
ExpiresByType text/html A2592000
ExpiresByType text/xml A2592000
ExpiresByType text/css A2592000
ExpiresByType text/plain A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
ExpiresByType image/bmp A2592000
ExpiresByType application/x-shockwave-flash A2592000

<FilesMatch "\.(html?|txt)$">
  ForceType 'text/html; charset=UTF-8'
</FilesMatch>

<FilesMatch "\.(css)$">
  ForceType 'text/css; charset=UTF-8'
</FilesMatch>

<FilesMatch "\.(js)$">
  ForceType 'text/javascript; charset=UTF-8'
</FilesMatch>

<FilesMatch "\.(css|js)$">
  Header append Vary Accept-Encoding
</FilesMatch>

但是,当我运行测试页会显示如下-----

But when I run the page test it shows the following -----

Compressing the following resources with gzip could reduce their transfer size by 882B (48% reduction).

Compressing http://wooflux.co.cc/ could save 645B (48% reduction).
Compressing http://wooflux.co.cc/style.css could save 237B (51% reduction).

不过,我已经做了 GZIP COM pression我的的.htaccess 文件。我也不是什么让错在这里,顺便说一句,我很新的这个编码风格。所以,请让我知道如果我做任何错误或没有。

But I have done gzip compression on my .htaccess file. I don't what is getting wrong here, and by the way I'm very new to this coding style. So please let me know if I'm doing any error or not.

推荐答案

我还没有使用mod_gzip的,但这里是我的.htaccess我通过使用mod_deflate模块来gzip压缩的.js,.css和其他文件:

I have not used mod_gzip but here is my .htaccess I use to gzip .js, .css and other files via mod_deflate:

#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x- javascript application/javascript
</ifmodule>
#End Gzip

如果你是不是已经意识到这一点,萤火虫是因为如果下载的内容是gzip压缩的检查非常有用的。点击Firebug的网络选项卡,然后做移-F5让火狐重新加载所有的.js和.css文件,使他们表现出的净面板。点击+旁边的.js或者.css文件,然后点击标题选项卡。如果响应gzip压缩的,你会看到在响应头节内容编码gzip的。我像IE浏览器,Safari浏览器和Chrome等同提供相同的能力。

In case you are not already aware of it, Firebug is very useful for checking if downloaded content is gzipped. Click on the "Net" tab in Firebug and then do shift-f5 to get Firefox to reload all the .js and .css files so they show in the Net panel. Click the "+" next to the .js or .css file and click the "Headers" tab. If the response is gzipped you will see "Content-Encoding gzip" in the Response Headers section. I image the IE, Safari, and Chrome equivalents offer the same ability.

有关于使用gzip压缩的.js和IE6 .css文件要提防有一个问题。我认为这是只适用于IE6 SP1的用户。

There is one gotcha regarding gzipping .js and .css files on IE6 to watch out for. I think it is only applicable to IE6 SP1 users.

这篇关于Gzip已融为一体pression通过的.htaccess不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆