以下可缓存资源的生命周期较短 - Google字体

时间:2016-11-01 18:56:37

标签: javascript html wordpress .htaccess caching

您好我正在使用https://tools.pingdom.com测试我的wordpress网站速度,我有一个F for Leverage浏览器缓存,它说:

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

https://ssl.google-analytics.com/ga.js

https://fonts.googleapis.com/css?family=Droid+Sans

https://fonts.googleapis.com/css?family=Lora

https://fonts.googleapis.com/css?family=Merriweather+Sans:300,400,700

我还需要将哪些内容添加到.htaccess文件中?我已经有了这个:

到期高速缓存

ExpiresActive On

ExpiresByType image / jpg“访问1周”

ExpiresByType image / jpeg“访问1周”

ExpiresByType image / gif“access 1 year”

ExpiresByType image / png“访问1周”

ExpiresByType text / css“access 2 month”

ExpiresByType application / pdf“access 2 year”

ExpiresByType text / x-javascript“access 2 month”

ExpiresByType应用程序/ x-shockwave-flash“访问2个月”

ExpiresByType image / x-icon“访问2年”

ExpiresDefault“访问2天”

ExpiresByType video / mp4“访问2年”

到期高速缓存

1 个答案:

答案 0 :(得分:5)

只有这样才能下载样式表/字体并将其添加到您的服务器,因为您不会影响Google的1天过期标题。

打开https://fonts.googleapis.com/css?family=链接并获取各种字体,例如:https://fonts.gstatic.com/s/droidsans/v6/s-BiyweUPV0v-yRb-cjciPk_vArhqVIZ0nv9q090hN8.woff2

下载并将其保存到您的服务器。现在,您可以使用与Google样式表相同的样式,但在您自己的css文件中。确保将fonts.gstatic.com链接更改为服务器上的文件。

如果您不想这样做,那么处理您的请求的更好方法是这样的:

<link rel="dns-prefetch" href="//fonts.googleapis.com">
<link rel="dns-prefetch" href="//ssl.google-analytics.com">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Droid+Sans|Lora|Merriweather+Sans:300,400,700">
<script src="//ssl.google-analytics.com/ga.js" async></script>

编辑12/2:你不想这样做的原因是因为谷歌可能会更新字体,但字体实际上并不经常更新。

相关问题