Next.js Image Optimization

Resolve Cumulative Layout Shifts (CLS) and Largest Contentful Paint (LCP) bottlenecks in Next.js applications.


Fixing CLS (Cumulative Layout Shift)

Next.js requires image dimensions to reserve screen slots, preventing sudden jumps. If you do not have sizes beforehand, use AssetFlow's command to generate width dimensions or optimize static assets before build.

tsx
import Image from "next/image"; import localHero from "@/public/dist/hero-1280.webp";  export default function Hero() { return ( <div className="relative w-full h-[400px]"> <Image src={localHero} alt="Hero Banner" placeholder="blur" priority /> </div> ); }

Resolving LCP Performance Warnings

LCP assets must load as fast as possible. Avoid lazy loading above-the-fold banners by appending the priorityproperty to your `<Image>` component, which preloads the image during initial document paint.