Wydajność
perf/font-display
Every @font-face and Google Fonts URL sets font-display (swap or optional) so text is visible while the font loads.
drobnastatycznefe-fonts
Dlaczego
Without font-display, browsers may hide text for up to a few seconds while a web font downloads, so the page looks empty and the Largest Contentful Paint can wait for the font.
Poprawka
Add font-display: swap to show fallback text at once, or font-display: optional when you would rather keep the fallback than shift the layout. Pick a fallback with similar metrics, or adjust it with size-adjust. For Google Fonts, add &display=swap to the stylesheet URL.
Przykłady
/* bad */
@font-face { font-family: Inter; src: url(/inter.woff2) format("woff2"); }
/* good */
@font-face { font-family: Inter; src: url(/inter.woff2) format("woff2"); font-display: swap; }Źródła
Fakty
- Identyfikator
perf/font-display- Waga
- drobna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
cssscsslesshtmlvuesvelteastro- Ten sam problem w
- Lighthouse
font-display-insight - Uczy jej skill
fe-fontsWeb fonts- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain perf/font-display