Loading…
Loading…
Optimize images in Next.js with the Image component, blur placeholders, responsive sizes, and remote image configuration for faster page loads.
Tags
This is part of the AI Automation Engineer Roadmap series.
Use the priority prop for LCP images, set proper sizes, add blur placeholders, and configure remote domains to get automatic format conversion and responsive serving for free.
Your Next.js site ships large, unoptimized images. The hero banner loads as a 2MB PNG, below-the-fold images load eagerly, and Lighthouse flags your LCP as slow. You know next/image helps, but the default settings leave performance on the table.
Images frequently dominate page weight, especially on marketing pages, blog indexes, and project galleries. That means image handling affects:
The good news is that Next.js solves a lot of this automatically. The bad news is that automatic optimization only works well if you provide the right inputs.
priorityimport Image from "next/image";
// Hero image - above the fold, critical for LCP
<Image
src="/hero.jpg"
alt="Hero banner"
width={1200}
height={600}
priority // Disables lazy loading, adds preload link
/>Only use priority on the largest above-the-fold image. Using it everywhere defeats lazy loading.
Use priority for:
Do not use it for:
sizes// Without sizes: browser downloads the largest image
<Image src="/card.jpg" alt="Card" width={800} height={400} />
// With sizes: browser picks the right size for the viewport
<Image
src="/card.jpg"
alt="Card"
width={800}
height={400}
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
/>Without sizes, the browser assumes the image is full-viewport width and downloads an oversized version.
This is one of the most commonly missed optimizations. If you use responsive layouts and omit sizes, the browser often downloads more image than the layout actually needs.
// Static import - blur works automatically
import heroImg from "@/public/hero.jpg";
<Image src={heroImg} alt="Hero" placeholder="blur" />
// Remote image - provide a tiny base64 placeholder
<Image
src="https://cdn.example.com/photo.jpg"
alt="Photo"
width={600}
height={400}
placeholder="blur"
blurDataURL="data:image/jpeg;base64,/9j/4AAQSkZJRg..."
/>Blur placeholders improve perceived performance and make transitions feel smoother, especially on slower networks. They also help maintain layout stability when image dimensions are known.
Use them for:
Do not overthink them for tiny icons or decorative assets where the effect is negligible.
// next.config.ts
const config: NextConfig = {
images: {
remotePatterns: [
{
protocol: "https",
hostname: "cdn.example.com",
pathname: "/images/**",
},
],
},
};If you load remote images, configuration is part of correctness, not just optimization. Without it, the app may fail to optimize the image at all.
This is also where teams should stay strict. Allow only the domains or URL patterns you actually need.
One of the easiest ways to cause layout shift is to render images without a stable box.
Good patterns:
width and heightEven when the image itself loads lazily, the page should already know how much space to reserve.
Not every image on the site deserves the same treatment.
Examples:
The performance win often comes from choosing a more appropriate source asset before next/image does any processing.
priority Too OftenThis turns off lazy loading and can make the initial page load heavier, which defeats the point.
sizes on Responsive ImagesThis is one of the biggest silent performance mistakes in Next.js image usage.
If remote image patterns are too broad, you make it easier to accidentally ship oversized or unexpected assets.
next/image as a Magic FixThe component helps a lot, but it does not compensate for poor source assets, missing layout constraints, or weak responsive strategy.
If you want a simple image performance checklist:
prioritysizes for responsive layoutsThat workflow catches most of the high-value issues without turning image optimization into a rabbit hole.
The next/image component generates multiple image sizes at build time and serves the optimal format (WebP or AVIF) based on the browser's Accept header. The sizes attribute tells the browser which image to download before layout is computed. The priority prop injects a <link rel="preload"> tag in the document head, starting the download before React hydrates. Blur placeholders reserve the exact space in layout, preventing Cumulative Layout Shift.
next/image gives you strong defaults, but the real gains come from using it intentionally. Set priority only where it matters, define sizes honestly, preserve layout stability, and treat source-asset choice as part of performance work, not something separate from it.
Collaboration
I help startups and established companies design, build, and scale world-class digital products. From deep technical architecture to pixel-perfect UI: let's bring your vision to life.
Five essential built-in generic utility types in TypeScript that will save you hundreds of lines of code.
Generate dynamic Open Graph images in Next.js using the ImageResponse API with custom fonts, gradients, and data-driven content for social sharing.
Create reusable GitHub Actions workflows with inputs, secrets, and outputs to eliminate YAML duplication across repositories and teams efficiently.