html - 预加载字体时不能让所有浏览器都满意 - 控制台错误
问题描述
我一直在尝试预加载字体,无论我如何编写它,Chrome 或 Firefox 都会引发某种控制台错误。
情况1
<link rel="preload" href="/fonts/open-sans-v26-latin-regular.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/fonts/RobotoCondensed-Regular.ttf" as="font" type="font/truetype" crossorigin>
火狐:
Error 1
Preload of /fonts/RobotoCondensed-Regular.ttf was ignored due to unknown “as” or “type” values, or non-matching “media” attribute.
Error 2
The resource at “/fonts/open-sans-v26-latin-regular.woff2” preloaded with link preload was not used within a few seconds. Make sure all attributes of the preload tag are set correctly.
The resource at “/fonts/RobotoCondensed-Regular.ttf” preloaded with link preload was not used within a few seconds. Make sure all attributes of the preload tag are set correctly.
铬合金:
<link rel=preload> has an unsupported `type` value
The resource /fonts/open-sans-v26-latin-regular.woff2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.
案例 2(此处删除许多线程上推荐的类型)
<link rel="preload" href="/fonts/open-sans-v26-latin-regular.woff2" as="font" crossorigin>
<link rel="preload" href="/fonts/RobotoCondensed-Regular.ttf" as="font" crossorigin>
火狐:
The resource at “/fonts/open-sans-v26-latin-regular.woff2” preloaded with link preload was not used within a few seconds. Make sure all attributes of the preload tag are set correctly.
The resource at “/fonts/RobotoCondensed-Regular.ttf” preloaded with link preload was not used within a few seconds. Make sure all attributes of the preload tag are set correctly.
铬合金:
The resource /fonts/open-sans-v26-latin-regular.woff2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.
The resource /fonts/RobotoCondensed-Regular.ttf was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.
如何使这些控制台错误消失?页面加载时会立即显示字体。
解决方案
推荐阅读
- mit-scratch - Set X() 和 Set Y() 块在 Scratch 中不起作用
- angularjs - NgMask 强制自定义模式
- java - 如何在地址为 46.XXX.XX.XX:8008/ 的页面中下载 java 小程序类文件
- python - 用于多标签分类问题的 tf-idf 矢量化器
- avr - 使用单独的时序控制多个 PWM
- reactjs - 有没有办法在地图上的反应传单中显示下拉菜单
- swift - Firebase 和 Swift 限制帖子编号错误
- c++ - constexpr 结构成员初始化
- javascript - 如何修复将内容覆盖到其一侧的 Bootstrap 下拉菜单?
- c - 在 Linux 的特定 CPU 上运行进程?(不能用命令行指定)