我从Google Speed测试中收到此错误:
以下可缓存资源的新鲜生命周期较短。为以下资源指定将来至少一周的到期时间:
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文件中做些什么吗?
答案 0 :(得分:4)
看起来静态文件没有设置过期。阅读 - 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
答案 1 :(得分:0)
PageSpeed:利用浏览器缓存 每次浏览器加载网页时,都必须下载所有Web文件才能正确显示页面。这包括所有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 ##