html - 谷歌字体加载优化和缓存

标签 html fonts pagespeed google-font-api google-fonts

Google 的页面速度测试只显示一个问题:

Eliminate render-blocking JavaScript and CSS in above-the-fold content Your page has 1 blocking CSS resources. This causes a delay in rendering your page.
None of the above-the-fold content on your page could be rendered without waiting for the following resources to load. Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML.
Optimize CSS Delivery of the following:
https://fonts.googleapis.com/css?family=Roboto:300,400

按照 fonts.google.com 推荐的方式加载的字体:

<link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">

<head />内标签。

据我所知,无法控制 google 的字体缓存,而且此 url 的输出取决于用户代理,因此在本地分发字体没有意义。所以,问题是:我想用它做什么?我如何满足谷歌的速度测试?

最佳答案

到目前为止,我知道如果您使用 Fontloader 是目前最好的解决方案.它首先加载一个简短的 .js 脚本,然后异步加载字体。
提示:Use font-family: 'Roboto', 'sans serif'; async 存在网站呈现后字体类型切换的问题。所以用户看到一个简短的字体切换就像一闪而过。如果您使用无衬线字体作为回退,则开关不会太大。
或者使用 .wf-active

关于html - 谷歌字体加载优化和缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44216622/

相关文章:

javascript - 定位 Lightbox2 关闭按钮时遇到问题

html - 导航栏和固定 float 联系栏点击并保持打开,以及更改字体

linux - 如何从 Ghostscript 更新 CID 字体

caching - 使用 Cloudfront 时,如何设置相对于当前日期的过期 header ?

javascript - 使用 script 标签延迟加载 HTML 小部件

html - 有没有办法让 Chris Coyier 的响应式 "list"表具有动态内容?

html - 显示 :table when width of content is more then outer div

javascript - 文本到语音与化身口型同步,无插件

css - @font-face 在其他计算机上不工作 - 具有正确的文件链接

javascript - Google PageSpeed Insights 表示我的网站很重。外部模式是解决方案吗?