Batch WebP Assets for Next.js & React: Core Web Vitals Guide
Your Lighthouse score has one dominant lever and it's the hero image. The local-first workflow: right-sized WebP assets, the public/ trap, next/image done right, and batching 100+ files before they ever reach git.
The trap: public/ ships whatever you commit
Next.js optimizes only images rendered through next/image. Everything in public/ — referenced by plain <img>, CSS, favicons, OG images — ships byte-for-byte, including that 3MB designer PNG. The fix is a pre-commit habit, not a plugin:
- Export at displayed size (heroes 1200–1920px, thumbs 400–800px) — never ship 4K sources.
- WebP quality 80 default; 85–90 for text-heavy graphics; AVIF hand-tuned for heroes.
- Keep the PNG/JPG master out of the repo; commit only the optimized delivery file.
Quick Solution
Assets folder → web-ready in one pass.
Sharp scripts work, but someone has to write and maintain them per project. Formatif Pro ($8.95 one-time) runs a saved “web-80” recipe over any assets folder — resize cap, WebP at quality 80, per-file before/after sizes — offline, no build-step dependency, no per-image fees. Re-run before every release.
next/image done right (4 props that fix most LCP fails)
next.config — serve AVIF first, WebP fallback
images: { formats: ["image/avif", "image/webp"] }- priority on the hero image only — it preloads the LCP element; putting it everywhere backfires.
- sizes matching your layout so browsers fetch the right variant, not the largest.
- Explicit width/height (or fill with a sized parent) to kill layout shift (CLS).
- placeholder='blur' with a tiny blurDataURL for perceived speed on slow networks.
Still failing LCP after all four? The source file is the problem — no props fix a 4MB hero. Shrink the source (above), then re-test. For format fundamentals, see our WebP vs AVIF guide.
The 100-file path: script vs batch app
Sharp one-liner per file (sharp(input).resize(1600).webp({quality: 80}).toFile(out)) wired into a build script is free and version-controlled — best when the whole team runs Node. A desktop batch run is best when assets arrive from designers as chaotic folders: same resize + WebP-80 recipe, visual spot-check at 100% zoom, done in minutes with no code to maintain.
Web performance image questions, answered
Does Next.js optimize public/ images?
No — public/ ships as-is. Only next/image outputs get resizing and modern formats. Pre-optimize before commit.
WebP or AVIF in Next.js?
Both: formats: ['image/avif', 'image/webp']. WebP default for assets, AVIF hand-tuned for heroes.
How do images hurt Core Web Vitals?
Oversized heroes wreck LCP; unsized images cause CLS. Right-sized modern formats + width/height + hero priority.
What export size for web?
Largest displayed size: heroes 1200–1920px, thumbs 400–800px. 1920px WebP q80 ≈ 100–200KB.
Batch 100+ images to WebP?
Sharp script in build, or saved 'web-80' batch recipe over the folder. Spot-check text graphics at 100%.
LCP still slow with next/image?
Hero priority prop, sizes attribute, loader config — then shrink the source file itself. Props can't fix 4MB.
Keep learning
Green Lighthouse, every release.
Formatif Pro ($8.95 one-time) and Formatif AI ($12.95 one-time) handle video, image, and audio conversion offline — with batch workflows, no file size limits, and a 3-day free trial.
Sharp scripts are free and version-controlled — pick whichever fits how your assets arrive.
Written by
Founder of Formatif, a local-first offline media processing suite for Windows and Linux. Hadi writes about video, image, and audio formats, compression, and privacy-first desktop workflows.