</bijayShrestha>./lets-talk
← cd ..
~/blog/optimizing-images-in-nextjs.md

bijay@nepal:~/blog$ cat optimizing-images-in-nextjs.md

Optimizing images in Next.js without thinking about it

commit 6476922Author: Bijay Shrestha1 min read

#nextjs#performance

My portfolio screenshots were 3–5 MB PNGs, 2940px wide. On a phone, every one of them was downloaded at full size. The fix took three small changes.

## 1. Always pass sizes

Without a sizes prop, the browser assumes the image fills the whole viewport and picks a huge source. Telling it the real layout width lets it choose a much smaller file.

<Image
  src="/project.png"
  alt="Project screenshot"
  fill
  sizes="(min-width: 1024px) 60vw, 100vw"
/>

## 2. Turn on AVIF and WebP

// next.config.mjs
images: {
  formats: ["image/avif", "image/webp"],
}

## 3. Prioritise only what’s above the fold

Mark the hero image with priority so it loads first, and let everything else lazy-load by default.

EOF — thanks for reading. Questions? [email protected]