.htaccess帮助调整gZip和Expires值

时间:2012-02-15 20:22:17

标签: .htaccess gzip

YSlow报道说: 使用gzip压缩组件的等级F

有12个纯文本组件应该压缩发送

http://www.mysite.com/css/c/style
http://www.mysite.com/css/c/dd.css
http://www.mysite.com/css/c/jqueryslidemenu.css
http://www.mysite.com/assets/js/browser-detection.css
http://www.mysite.com/assets/js/jquery-1.6.min.js
http://www.mysite.com/assets/js/jquery.dd.js
http://www.mysite.com/images/jquery.pngFix.pack.js
http://www.mysite.com/assets/js/jqueryslidemenu.js
http://www.mysite.com/assets/js/browser-detection.js
http://www.mysite.com/assets/js/cufon-yui.js
http://www.mysite.com/assets/js/Futura_Bk_BT_400.font.js
http://www.mysite.com/store/ajax/getpubs.php

有32个静态组件没有远期到期日期。

(2012/2/17) http://www.mysite.com/css/c/style
(2012/2/17) http://www.mysite.com/css/c/dd.css
(2012/2/17) http://www.mysite.com/css/c/jqueryslidemenu.css
(no expires) http://www.mysite.com/assets/js/browser-detection.css
(2012/2/15) http://www.google-analytics.com/ga.js
(no expires) http://www.mysite.com/assets/js/jquery-1.6.min.js
(1997/7/26) http://www.mysite.com/j/banner_slides
(1997/7/26) http://www.mysite.com/j/multi-click-slider
(no expires) http://www.mysite.com/assets/js/jquery.dd.js
(no expires) http://www.mysite.com/images/jquery.pngFix.pack.js
(no expires) http://www.mysite.com/assets/js/jqueryslidemenu.js
(no expires) http://www.mysite.com/assets/js/browser-detection.js
(no expires) http://www.mysite.com/assets/js/cufon-yui.js
(no expires) http://www.mysite.com/assets/js/Futura_Bk_BT_400.font.js
(no expires) http://www.mysite.com/assets/js/fonts.js
(1997/7/26) http://www.mysite.com/j/jquerycourseslide.js
(no expires) http://www.mysite.com/images/menu_bg.png
(no expires) http://www.mysite.com/images/menuArrowYellow.png
(no expires) http://www.mysite.com/images/menuArrowGrey.png
(no expires) http://www.mysite.com/images/bgHomeBanner.png
(no expires) http://www.mysite.com/images/btnHomeBannerLeft.png
(no expires) http://www.mysite.com/images/btnHomeBannerRight.png
(no expires) http://www.mysite.com/images/btnLeft.png
(no expires) http://www.mysite.com/images/btnRight.png
(no expires) http://www.mysite.com/images/select-base.png
(no expires) http://www.mysite.com/images/select-cap.png
(no expires) http://www.mysite.com/images/iconComments.png
(no expires) http://www.mysite.com/images/bgRSS.png
(no expires) http://www.mysite.com/images/bgFooter.png
(no expires) http://www.mysite.com/files/Subscriptionad4.jpg
(no expires) http://www.mysite.com/images/favicon.ico
(2000/4/19) http://www.google-analytics.com/__utm.gif?...

我已将此添加到我的.htaccess:

<IfModule mod_headers.c>
  Header unset ETag
  Header unset Last-Modified
</IfModule>
FileETag None

<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
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
  Header append Vary User-Agent env=!dont-vary
</IfModule>

<Files *.php>
  SetOutputFilter DEFLATE
</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>

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
</IfModule>

为了避免上述报告,需要进行哪些调整?

注意:这些是由ExpresssionEngine提供的链接,作为没有扩展名的模板:

http://www.mysite.com/css/c/style
http://www.mysite.com/j/banner_slides
http://www.mysite.com/j/multi-click-slider

ExpressionEngine gZip输出设置为是。

1 个答案:

答案 0 :(得分:0)

确保您对页面进行了硬刷新(ctrl + F5)。我注意到YSlow使用缓存的标题信息,因此没有显示正确的信息。

还要确保已启用相应的apache模块。通过删除ifmodule标签来检查这一点(mod_gzip除外,你可以完全删除哪个部分)。

我认为YSlow要求到期后至少有7天到期,所以至少604800秒。

同时删除该行:Header unset Last-Modified,除非您知道它的作用并具有特殊目的。