next/image · public/ · Local

Optimize Next.js Images — Give next/image a Lean Source

next/image optimizes on request, and only for images it serves. Compress the originals in public/ so the first request is fast, and plain <img> files are small too.

Quick answer

next/image resizes and converts images through Next's Image Optimization API, caching the result. It always starts from your original file, and with output: 'export' there is no server to do that work at all. Compress public/ with TinyPixels so both paths start from a lean source.

How to compress images before deploying a Next.js app

1

Download and open TinyPixels

Free to install on Mac or Windows — no account needed to start.

2

Resize oversized originals

A 6000 px export makes the first optimized request slower and bloats the cache.

3

Compress public/

Drop it into TinyPixels. Convert big banners to WebP or AVIF if you serve them directly.

4

Commit and deploy

Both the optimizer and the raw files now start from smaller sources.

What next/image does, and what it leaves alone

next/image resizes and converts images on demand through the Image Optimization API: the first request for a given size transforms the original, serves WebP by default (AVIF if you enable it in images.formats), and caches the result for later visitors. Static imports also give it width and height automatically, and a blur placeholder if you ask for one.

That makes the original's size matter in two ways. A very large source makes the first request for each variant slower and takes more memory on the server. And everything that bypasses the optimizer, plain <img> tags, CSS backgrounds, Open Graph images and files served from public/ directly, ships the original at full size.

Static exports change the picture further: with output: 'export' there is no server, so the default optimizer is unavailable. Unless you configure a custom loader or mark images as unoptimized, your images ship as committed, and compressing them beforehand is the optimization. Check the current Next.js docs for your version's details, and your hosting provider's terms on image optimization usage.

Faster first request

A lean source shortens the on-demand transform for each new size.

Covers unoptimized paths

Plain <img>, CSS and OG images get smaller too.

Key for static export

With output: export, pre-compression is the main optimization you have.

Format conversion

Convert directly-served banners to WebP or AVIF and update references.

What Next.js does with an image

SetupWhat happensYour move
<Image /> with the default serverResizes on request, WebP by default, AVIF opt-in, caches the output.Give it a lean, right-sized source
Static import (import hero from ...)Infers width and height, supports a blur placeholder. Still starts from the original.Compress the imported file
output: 'export'No server for the default optimizer. Images ship as committed unless you set a loader or unoptimized.Compress before build; this is your optimization
Plain <img> or CSS url()Not optimized. The original is served.Compress the file
Open Graph / metadata imagesServed as-is.Compress the file

Defaults depend on your Next.js version and hosting setup; confirm against the current docs before relying on any one behaviour.

Common mistakes with Next.js images

Assuming next/image makes compression unnecessary

It still reads your original on the first request. A 6 MB source means a slow first hit and a bigger cache, even though visitors later get small variants.

Using output: 'export' without a loader

The default optimizer needs a server. Without a custom loader or unoptimized, you will get a build error or unoptimized full-size images.

Using a plain <img> for the hero

It bypasses the optimizer entirely, so the original file is what the visitor gets.

Forgetting CSS and OG images

Backgrounds and social-card images are served directly, and nothing optimizes them unless you do.

Frequently asked questions

Does next/image compress my images?

It resizes and converts them on request and caches the result, but it reads your original each time it creates a new variant. A smaller original makes that work faster.

Do I still need to compress images if I use next/image?

Yes, for three reasons: faster first requests, images that bypass the optimizer, and static exports where no server optimizer exists.

How do images work with output: 'export'?

There's no server to run the Image Optimization API, so you need a custom loader or unoptimized images. Compressing the sources before build is the practical optimization.

Does next/image support AVIF?

Yes, you can enable AVIF through the images.formats setting; WebP is the default. Check the docs for your version.

Can I batch compress my whole public/ folder at once?

Yes. Drop public/ into TinyPixels and every image compresses in one local pass.

Ship a leaner Next.js deploy

Free to start. No credit card, no account, no cloud. See Pro pricing →