Performance: Image component and optimization
This affects page load speed by optimizing image delivery and reduces layout shifts by reserving space for images.
import Image from 'next/image'; <Image src="/photo.jpg" alt="Photo" width={800} height={600} priority />
<img src="/photo.jpg" alt="Photo" style={{ width: '100%' }} />
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Standard <img> tag with full-size image | Minimal DOM nodes | Multiple reflows due to layout shifts | High paint cost from large images | [X] Bad |
| Next.js Image component with fixed size and lazy loading | Minimal DOM nodes | Single reflow due to reserved space | Lower paint cost from optimized images | [OK] Good |
Image component instead of a regular <img> tag?import Image from 'next/image';.src, alt, width, and height props with correct casing and types.width and height props?import Image from 'next/image';
export default function Photo() {
return <Image src='photo.png' alt='Photo' width={400} height={300} />;
}src path to be absolute or start with a slash for public folder images.src path is relative but missing a leading slash. -> Option Apriority prop tells Next.js to load the image eagerly for faster display on page load.placeholder='blur' prop shows a blurred version of the image while the full image loads.priority and placeholder='blur' -> Option BPass the test and this pattern moves unknown