Performance: Responsive images
Responsive images affect page load speed by delivering appropriately sized images for different screen sizes, reducing data usage and improving Largest Contentful Paint (LCP).
import Image from 'next/image'; export default function Page() { return ( <Image src="/photo.jpg" alt="Photo" sizes="(max-width: 600px) 480px, 800px" width={800} height={533} priority /> ); }
import Image from 'next/image'; export default function Page() { return <Image src="/photo.jpg" width={1200} height={800} alt="Photo" />; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed large image | 1 image node | 1 reflow | High paint cost due to large decode | [X] Bad |
| Responsive image with sizes | 1 image node | 1 reflow | Lower paint cost with smaller decode | [OK] Good |
import Image from 'next/image';
export default function Photo() {
return (
<Image
src='/photo.jpg'
alt='A photo'
sizes='(max-width: 600px) 100vw, 50vw'
width={800}
height={600}
/>
);
}import Image from 'next/image';
export default function Banner() {
return (
<Image
src='/banner.png'
alt='Banner'
width='100%'
height='300'
/>
);
}Pass the test and this pattern moves unknown