【发布时间】:2020-11-03 11:01:31
【问题描述】:
我正在对PageSpeed Insights 进行诊断
Ensure text remains visible during webfont load
Leverage the font-display CSS feature to ensure text is user-visible while webfonts are loading. Learn more.
URL
Potential Savings
…v1/aWB4m0aac….woff2(fonts.gstatic.com) 10 ms
…v21/nuFvD-vYS….woff2(fonts.gstatic.com) 10 ms
…v13/6xK3dSBYK….woff2(fonts.gstatic.com) 10 ms
我正在尝试通过更改来纠正它
<link rel="stylesheet" href="https://fonts.googleapis.com" />
到
<link rel="stylesheet" href="https://fonts.googleapis.com/display=swap" />
但这实际上会引发控制台错误
我知道PageSpeed Insights recommends to add font-display: swap 到@fontface,但我不知道@fontface 是什么。
我正在使用 Bootstrap 和 Gatsby
我知道还有gatsby-plugin-web-font-loader。有没有办法使用它来避免这种诊断?
这些都是 font-family 出现在我的程序中的所有时间。我用的是scss,所以大部分都是变量
我只在我的程序中指定了一次字体,我认为 bootstrap 会在其余时间选择字体
blockquote > p {
font-family: 'Montserrat', sans-serif;
}
更新,我正在使用这个插件
{
resolve: `gatsby-plugin-google-fonts`,
options: {
fonts: [
`Montserrat`,
`Helvetica Neue`,
`Helvetica`,
`Arial`
],
display: 'swap'
}
},
【问题讨论】:
标签: javascript reactjs gatsby pagespeed pagespeed-insights