Wydajność
perf/img-dimensions
Every img has width and height attributes (or a CSS aspect ratio) so the browser reserves its space.
umiarkowanastatycznefe-images
Dlaczego
An image without dimensions takes no space until it loads, then pushes the content below it down. That shift counts against Cumulative Layout Shift, one of the Core Web Vitals, and makes people click the wrong thing.
Poprawka
Write the image's intrinsic size: <img src="hero.jpg" width="1200" height="600" alt="…">, and let CSS scale it with max-width: 100%; height: auto;. The browser derives the aspect ratio from the two attributes. Framework image components (next/image, @nuxt/image, astro:assets) do this when you pass the size.
Przykłady
<!-- bad -->
<img src="hero.jpg" alt="Our team">
<!-- good -->
<img src="hero.jpg" width="1200" height="600" alt="Our team">Źródła
Fakty
- Identyfikator
perf/img-dimensions- Waga
- umiarkowana
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
htmlangularvuesvelteastrojsx- Ten sam problem w
- Lighthouse
unsized-images - Uczy jej skill
fe-imagesImages and media delivery- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain perf/img-dimensions