我一直在创建一个网站,并通过gtmetrix.com检查它的速度。我使用了以下.htaccess
文件来压缩.js, .css
和更多文件。通过.htaccess Gzip压缩不起作用
<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>
但是当我运行该页面测试显示以下-----
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
压缩在我.htaccess
文件。我不会在这里发生什么问题,顺便说一下,我对这种编码风格很陌生。所以请让我知道如果我做错了或没有。
BTW,确保mod_gzip的和/或MOD_GZIP Apache模块安装。你也可能想检查Apache错误日志是否有任何适用的错误。 – 2011-05-01 06:06:28