Course map
Stage 1: App Router Foundations
Stage 2: The Rendering Model
Stage 3: Data, Caching and Mutations
Stage 4: Full-Stack Next.js
Stage 5: Production and Specialization

Part 04 / Topic 6 of 8

next/image: the same file, optimized

Section 5's file is also used through next/image, on Apna Bazaar's home page, via a static import rather than a plain string path:

import Image from "next/image";
import vaseImage from "../../../public/apna-bazaar-vase.png";

// ...
<Image src={vaseImage} alt="Jaipur Blue Pottery Vase, a bestseller at Apna Bazaar" style={{ maxWidth: "100%", height: "auto" }} />

A static import is what lets Next.js skip asking for explicit width/height props — the installed package's own guide: "If the image is statically imported, Next.js will automatically determine the intrinsic width and height... used to prevent Cumulative Layout Shift." Confirmed against the real rendered <img> tag:

$ curl -s http://localhost:PORT/store | grep -o '<img[^>]*alt="Jaipur Blue Pottery Vase[^>]*>'
<img alt="Jaipur Blue Pottery Vase, a bestseller at Apna Bazaar" loading="lazy" width="900" height="900" decoding="async" data-nimg="1" style="color:transparent;max-width:100%;height:auto" srcSet="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fapna-bazaar-vase.2nkaf-5u2-f5o.png&amp;w=1080&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fapna-bazaar-vase.2nkaf-5u2-f5o.png&amp;w=1920&amp;q=75 2x"/>

width="900" height="900" were never written by hand anywhere in this harness — they came straight from reading the actual PNG file at build time, matching its real 900×900 size. loading="lazy" and decoding="async" are also automatic, not configured.

The srcSet URLs route through /_next/image, Next.js's own on-demand image resizing endpoint. Fetched directly, with a browser-like Accept header:

$ curl -s -o resized.bin -D - "http://localhost:PORT/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fapna-bazaar-vase.2nkaf-5u2-f5o.png&w=1080&q=75" -H "Accept: image/webp,*/*" | grep -i content-type
content-type: image/webp
$ file resized.bin
resized.bin: RIFF (little-endian) data, Web/P image, VP8 encoding, 900x900, Scaling: [none]x[none], YUV color, decoders should clamp

A PNG went in; a WebP came back — the format conversion the installed package's own <Image> reference promises ("serving correctly sized images for each device, using modern image formats like WebP"). The width stayed at 900 even though w=1080 was requested, because Next.js never upscales past a source image's real resolution — this file's actual size is the ceiling.

Full file: examples/08-store-home-next-image.tsx.

Done here? The practice set for Part 4 — including the solutions — is on the part page.

Search the guide