Prefer to watch?
This article has a full video walkthrough on YouTube
Same content, live coding, 24 min — no fluff.
Why image optimization is critical
On a typical webpage, images make up over 60% of the total page weight. When users land on your site, unoptimized images cause massive Layout Shifts (CLS), high LCP times, and unnecessary data usage, especially on mobile networks.
The power of next/image
The Next.js Image Component extends the HTML <img> element with features for automated performance optimization:
- Size Optimization: Automatically serves correctly sized images for each device, using modern image formats like WebP and AVIF.
- Visual Stability: Prevents layout shift automatically when images are loading.
- Faster Page Loads: Images are only loaded when they enter the viewport using native browser lazy loading, with optional blur-up placeholders.
import Image from 'next/image'
export default function Profile() {
return (
<Image
src="/me.png"
alt="Author"
width={500}
height={500}
priority // Use priority for above-the-fold content!
/>
)
}
Advanced Optimization Tips
Always define the sizes attribute. It tells the browser how wide the image will render at different breakpoints so it doesn't load a huge file for a small thumbnail on mobile screens.