您好,我正在使用 https://tools.pingdom.com测试我的 wordpress 站点速度,我有一个 F 表示杠杆浏览器缓存,它说:
以下可缓存资源的新鲜度生命周期较短。为以下资源指定至少一周后的到期时间:
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 "访问 1 年"
ExpiresByType image/png "访问 1 周"
ExpiresByType 文本/css“访问 2 个月”
ExpiresByType 应用程序/pdf“访问 2 年”
ExpiresByType text/x-javascript "访问 2 个月"
ExpiresByType 应用程序/x-shockwave-flash “访问 2 个月”
ExpiresByType image/x-icon "访问 2 年"
ExpiresDefault "access 2 days"
ExpiresByType 视频/mp4“访问 2 年”
过期缓存
最佳答案
执行此操作的唯一方法是下载样式表/字体并将它们添加到您的服务器,因为您不能影响 Google 的 1 天到期 header 。
打开你的 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:您不想这样做的原因是 Google 可能会更新字体,但是,字体并不会经常更新。
关于javascript - 以下可缓存资源的新鲜度生命周期很短 - Google 字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40366787/