我正在使用html link rel preload标签预加载字体:
<link rel="preload" href="fonts/32ADEO.woff2" as="font" type="font/woff2">
虽然这确实首先加载字体,但chrome中的网络选项卡显示两次加载字体!?
我也收到以下警告:
The resource 07001 was
preloaded using link preload but not used within a few seconds from
the window’s load event. Please make sure it Please make sure it has
an appropriateas
value and it is preloaded intentionally.
我究竟做错了什么?
解决方法
preload-Tag采用“crossorigin”参数,必须为Webfonts提供,即使它们与您的网站位于同一主机上.
见https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content#Cross-origin_fetches或https://www.smashingmagazine.com/2016/02/preload-what-is-it-good-for/#early-loading-of-fonts.