Performance: Image optimization with astro:assets
HIGH IMPACT
This affects page load speed by reducing image file sizes and improving rendering time for images.
--- import { getImage } from 'astro:assets'; const optimizedImage = await getImage({ src: '/images/photo.jpg', width: 800, format: 'webp' }); --- <img src={optimizedImage.src} alt="Photo" loading="lazy" decoding="async" />
<img src="/images/photo.jpg" alt="Photo">
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unoptimized full-size images | Minimal | Triggers 1 reflow per image load | High paint cost due to large images | [X] Bad |
| astro:assets optimized images with lazy loading | Minimal | Single reflow after image loads | Low paint cost with smaller images | [OK] Good |