谷歌速度利用浏览器缓存


Google Speed Leverage browser caching

我从Google速度测试中得到了这个错误:

以下可缓存资源具有较短的新鲜度生命周期。为以下资源指定至少一个星期后的过期时间:

http://localhost/english/favicon.ico (expiration not specified)
http://localhost/english/images/bg_center.png (expiration not specified)
http://localhost/english/images/bg_top.jpeg (expiration not specified)
http://localhost/english/images/footer_bg2.png (expiration not specified)
http://localhost/english/images/m_facebook.png (expiration not specified)
http://localhost/english/images/m_rss.png (expiration not specified)
http://localhost/english/images/top_bg.png (expiration not specified)
http://localhost/english/javascript/gram.js (expiration not specified)
http://localhost/english/javascript/top_start.js (expiration not specified)
http://localhost/english/jquery.js (expiration not specified)
http://localhost/english/style/gram.css (expiration not specified)
http://localhost/english/style/style.css (expiration not specified)

我应该在我的htaccess文件做些什么吗?

看起来静态文件没有过期设置。阅读- http://www.absolutelytech.com/2010/08/02/howto-add-expire-headers-to-cache-static-files-using-htaccess/

你需要把下面的代码放到你的。htaccess

# Turn on the Expires engine
ExpiresActive On
# Expires after a month client accesses the file
ExpiresByType image/jpeg A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType text/plain A2592000
# Good for one week
ExpiresByType application/x-javascript M604800
ExpiresByType text/css M604800
ExpiresByType text/html M604800

pagesspeed:利用浏览器缓存每次浏览器加载网页时,它都必须下载所有的网络文件才能正确显示页面。这包括所有的HTML, CSS, javascript和图像。

要启用浏览器缓存,你需要编辑你的HTTP头来设置某些类型文件的过期日期。

找到你的。htaccess文件在你的域名的根目录,这个文件是一个隐藏的文件,但应该显示在FTP客户端,如FileZilla或CORE。您可以使用记事本或任何形式的基本文本编辑器编辑htaccess文件。

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##