首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Speed利用浏览器缓存

Google Speed利用浏览器缓存
EN

Stack Overflow用户
提问于 2011-07-23 01:50:02
回答 2查看 4K关注 0票数 2

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

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

代码语言:javascript
复制
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文件中做些什么吗?

EN

回答 2

Stack Overflow用户

发布于 2011-07-24 03:01:57

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

您需要在.htaccess中发布以下代码

代码语言:javascript
复制
# 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
票数 4
EN

Stack Overflow用户

发布于 2015-12-14 12:02:06

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

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

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

代码语言:javascript
复制
## 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 ##

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6794033

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档