Wydajność
perf/font-preload-crossorigin
A font preload has crossorigin (and type font/woff2); without it the preload is wasted and the font is fetched twice.
umiarkowanastatycznefe-fonts
Dlaczego
Browsers always fetch fonts in CORS mode, even from your own origin. A <link rel="preload" as="font"> without crossorigin is a non-CORS request, so it does not match: the browser downloads the font a second time when the CSS asks for it, and the preload only stole bandwidth.
Poprawka
Add crossorigin (anonymous) and type="font/woff2": <link rel="preload" href="/fonts/brand.woff2" as="font" type="font/woff2" crossorigin>. Preload only the one or two fonts used in the first view; frameworks such as next/font and @nuxt/fonts write the tag for you.
Przykłady
<!-- bad -->
<link rel="preload" href="/fonts/brand.woff2" as="font" type="font/woff2">
<!-- good -->
<link rel="preload" href="/fonts/brand.woff2" as="font" type="font/woff2" crossorigin>Źródła
Fakty
- Identyfikator
perf/font-preload-crossorigin- Waga
- umiarkowana
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
htmlangularvuesvelteastrojsx- Uczy jej skill
fe-fontsWeb fonts- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain perf/font-preload-crossorigin