我在Safari中使用YSlow尝试提高我的网站速度,并报告:
添加过期标题上的F级有9个静态组件没有远期过期日期。 (2014/5/29)http://fonts.googleapis.com/css?family=Trade+Winds (2012/4/15)http://mydomain.com/example.css
在html中添加过期标题的最佳做法是什么? 我的主机是GoDaddy,他们提供的.htaccess文件是空白的。
这是我迄今为止所尝试过的......
<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"
# cache.appcache needs re-requests
# in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Your document html
ExpiresByType text/html "access plus 0 seconds"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# RSS feed
ExpiresByType application/rss+xml "access plus 1 hour"
# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"
# Media: images, video, audio
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# HTC files (css3pie)
ExpiresByType text/x-component "access plus 1 month"
# Webfonts
ExpiresByType font/truetype "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
<IfModule mod_headers.c>
Header append Cache-Control "public"
</IfModule>
</IfModule>
答案 0 :(得分:2)
我自己想通了。解决方案不仅取决于您的主机(在我的情况下是GoDaddy),还取决于您拥有的帐户类型(在我的情况下是Linux Classic)。
我的解决方案是在我的ftp(明文)的根目录中创建一个.htaccess文件并粘贴以下内容:
<IfModule mod_expires.c>
# Activate mod_expires for this directory
ExpiresActive on
# locally cache common image types for 7 days
ExpiresByType image/jpg "access plus 7 days"
ExpiresByType image/jpeg "access plus 7 days"
ExpiresByType image/gif "access plus 7 days"
ExpiresByType image/png "access plus 7 days"
# cache CSS files for 24 hours
ExpiresByType text/css "access plus 24 hours"