Vercel 08 ▲ Image & Asset Optimization — Using Vercel Image Optimization, automatic WebP/AVIF negotiation, and asset caching
Images are typically the largest contributor to a webpage’s payload and the primary culprit behind poor Largest Contentful Paint (LCP) scores. On the web, delivering a high-resolution, unoptimized image to a mobile device is a waste of bandwidth and creates a poor user experience. Vercel solves this by implementing an intelligent Image Optimization API that intercepts image requests at the Edge, processes them on-the-fly, and caches the result for future users.
This chapter explores how Vercel manages assets through the next/image component and its underlying optimization engine. We will look at how the platform performs format negotiation, dynamically resizes images based on client requirements, and leverages the CDN to cache these transformed assets. By the end of this chapter, you will understand how to offload heavy image processing from your application code to the Vercel infrastructure, ensuring your site remains fast regardless of the complexity or volume of its media content.
Key point: Vercel Image Optimization automatically detects the browser’s capabilities via the Accept header to serve the most efficient format (AVIF or WebP), while dynamically resizing images to the exact dimensions required by the client to minimize payload size and improve Core Web Vitals.
Why X exists
The bandwidth problem. High-resolution images often weigh several megabytes. Serving these raw files to mobile devices with limited data connections is inefficient and slows down page load times significantly.
The format fragmentation problem. Modern image formats like AVIF and WebP offer superior compression compared to legacy JPEG or PNG files. Managing manual conversion pipelines for every image in your assets folder is operationally complex and difficult to scale.
The layout shift problem. When a browser renders an image without knowing its dimensions, the surrounding content jumps as the image loads, causing Cumulative Layout Shift (CLS). The system must reserve space for images before they arrive.
The resizing-at-origin problem. Generating resized versions of images (thumbnails, mobile, desktop) at build time bloats your deployment size and increases build times exponentially as the image library grows.
The caching complexity. Images are immutable assets that benefit from being cached at the Edge. Managing cache headers and purge cycles for thousands of individual image variations is difficult without an automated CDN layer.
a. The Vercel Image component and the optimization pipeline
The next/image component is a high-level wrapper that communicates with the Vercel infrastructure. Instead of pointing to an image file directly, it points to an endpoint (usually /_vercel/image) that receives the source URL, the desired width, and the quality settings as query parameters.
// The component sends a request to the optimization API
<Image
src="/profile.jpg"
width={500}
height={500}
alt="Profile picture"
/>
When this component renders, it does not fetch the raw file. It initiates a request to the Vercel Edge, which downloads the original source, transforms it to the specified dimensions, converts it to the optimal format, and caches the result. This happens on-demand, meaning you do not need to store thousands of generated variations in your repository.
b. Format negotiation and quality control
The Vercel Image Optimization service inspects the Accept header of every incoming request. If a browser sends image/avif,image/webp, the platform converts the source image to AVIF, which provides superior compression. If the browser only supports WebP, it provides WebP, and falls back to JPEG or PNG only if necessary.
// Explicitly setting quality to balance visual fidelity and size
<Image
src="/hero.png"
width={1200}
height={600}
quality={75} // Default is 75, can range from 1 to 100
alt="Hero image"
/>
You can control this behavior using the quality prop. While 75 is the default and usually optimal, you can tune it per image. Because the transformation happens on the edge, you can adjust these parameters in your code and immediately see the impact without needing to rebuild or re-upload your source assets.
c. Asset caching and remote patterns
Optimized images are cached at the Vercel CDN using s-maxage headers. This ensures that once an image is transformed (e.g., resized to 500px width in AVIF), that variation is served instantly to all subsequent users from the closest edge node.
// next.config.mjs
export default {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 's3.amazonaws.com',
pathname: '/my-bucket/**',
},
],
},
};
Remote images must be explicitly allowed via remotePatterns to prevent unauthorized domains from using your Vercel project’s optimization resources (DDoS protection). Once configured, remote images are treated exactly like local ones, benefiting from the same caching and format negotiation benefits.
Complete Example Session
// ============================================
// PART 1: BASIC USAGE (RESERVES SPACE)
// ============================================
<Image src="/logo.png" width={200} height={100} alt="Logo" />
// ============================================
// PART 2: RESPONSIVE FILL (CONTAINER SIZING)
// ============================================
<div style={{ position: 'relative', width: '100%', height: '400px' }}>
<Image src="/banner.jpg" fill style={{ objectFit: 'cover' }} alt="Banner" />
</div>
// ============================================
// PART 3: PRIORITY FOR LCP
// ============================================
<Image src="/hero.jpg" width={800} height={400} priority alt="LCP Image" />
// ============================================
// PART 4: RESPONSIVE SIZES ATTRIBUTE
// ============================================
<Image
src="/photo.jpg"
width={800}
height={600}
sizes="(max-width: 768px) 100vw, 800px"
alt="Photo"
/>
These parts covered basic image rendering, responsive layouts using fill, prioritizing images for LCP metrics, and optimizing bandwidth using the sizes attribute.
Quick Reference
Essential Props
| Prop | Usage | Description |
|---|---|---|
src | Required | URL or import of the image |
width | Required | Width in pixels |
height | Required | Height in pixels |
alt | Required | Accessibility text |
fill | Optional | Fills parent container |
priority | Optional | Preloads for LCP |
Format Negotiation
| Header | Format | Logic |
|---|---|---|
image/avif | AVIF | Highest compression |
image/webp | WebP | High compression |
| Default | PNG/JPEG | Fallback |
Configuration Options
| Option | Location | Purpose |
|---|---|---|
remotePatterns | next.config.js | Domain allowlisting |
deviceSizes | next.config.js | Breakpoints |
loader | next.config.js | Custom CDN |
Best Practices
✅ Do This:
// Always provide alt text for accessibility // ✅
<Image src="/a.jpg" alt="Description" ... /> // ✅
// Use priority for images above the fold // ✅
<Image src="/hero.jpg" priority ... /> // ✅
// Use sizes to help the browser choose resolution // ✅
<Image sizes="(max-width: 768px) 100vw, 50vw" ... /> // ✅
// Use remotePatterns for security // ✅
remotePatterns: [{ hostname: 'cdn.example.com' }] // ✅
❌ Don’t Do This:
// Don't leave alt text blank // ❌
<Image src="/a.jpg" alt="" ... /> // ❌
// Don't load non-LCP images with priority // ❌
<Image src="/footer.jpg" priority ... /> // ❌
// Don't use absolute sizing without aspect ratio // ❌
<Image width={500} ... /> // Missing height // ❌
// Don't expose all remote domains // ❌
remotePatterns: [{ hostname: '**' }] // ❌
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Layout Shift | Missing dimensions/fill | Add width/height |
| Image too large | Missing sizes | Add sizes attribute |
| 404/Error | Unregistered domain | Update remotePatterns |
| Blur effect delay | Heavy base64 | Check placeholder |
Real-World Examples
1. Static Import
import img from './photo.jpg';
<Image src={img} alt="Text" />
2. Remote Image
<Image src="https://example.com/i.jpg" width={500} height={500} alt="x" />
3. Fill Layout
<div className="relative h-64"><Image src="..." fill alt="x" /></div>
4. Priority
<Image src="..." width={100} height={100} priority alt="x" />
5. Custom Sizes
<Image sizes="(min-width: 808px) 50vw, 100vw" ... />
6. Blur Placeholder
<Image src="..." placeholder="blur" blurDataURL="..." alt="x" />
7. Quality adjustment
<Image src="..." quality={50} alt="x" />
8. Loading eager
<Image src="..." loading="eager" alt="x" />
9. Disabling optimization
<Image src="..." unoptimized alt="x" />
10. Aspect ratio
<Image src="..." width={16} height={9} alt="x" />
Visual
The Optimization Flow
┌──────────────────────────────────────────────┐
│ USER REQUEST │
│ │ │
│ [Browser: Accept: image/avif] │
│ │ │
│ VERCEL IMAGE SERVICE │
│ ┌──────────────────────┐ │
│ │ 1. Download Source │ │
│ ├──────────────────────┤ │
│ │ 2. Transform/Resize │ │
│ ├──────────────────────┤ │
│ │ 3. Convert to AVIF │ │
│ └──────────────────────┘ │
│ │ │
│ CDN CACHE (Served at Edge) │
└──────────────────────────────────────────────┘
Browser Format Negotiation
┌──────────────────────────────────────────────┐
│ BROWSER CAPABILITIES │
│ │
│ ┌──────────────┐ (Accept: image/avif) │
│ │ Chrome/Safari ───► YES, Serve AVIF │
│ └──────────────┘ │
│ │
│ ┌──────────────┐ (Accept: image/webp) │
│ │ Older Edge ───► YES, Serve WebP │
│ └──────────────┘ │
│ │
│ ┌──────────────┐ (No support) │
│ │ Legacy ───► Serve PNG/JPG │
│ └──────────────┘ │
└──────────────────────────────────────────────┘
Preventing Layout Shift
┌──────────────────────────────────────────────┐
│ WITHOUT NEXT/IMAGE │
│ [Text...] │
│ (Loading...) ──► [Big Image] ──► Text moves │
│ │
│ WITH NEXT/IMAGE │
│ [Text...] │
│ [Box reserved] ──► [Big Image] ──► No move │
│ │
│ Browser knows dimensions ahead of time │
└──────────────────────────────────────────────┘
Summary
| Item | Value |
|---|---|
| Core Tool | next/image |
| Primary Format | AVIF (Best compression) |
| Secondary Format | WebP |
| Layout Control | fill, sizes |
| Security | remotePatterns |
| LCP Fix | priority prop |
| Transformation | On-demand (not build-time) |
Key takeaways:
- On-demand transformation is scalable. Vercel processes images as they are requested, meaning your build times don’t grow when your media library grows.
- Format negotiation is automatic. The system uses the browser’s
Acceptheader to deliver the lightest possible file format without you changing a line of code. - Layout shift is a structural requirement. Always provide
widthandheightor usefillto reserve space and prevent visual jumping during page load. - Priority matters for LCP. Mark only your hero images or largest visible elements with the
priorityprop to ensure they are fetched immediately. - Security requires configuration. You must explicitly whitelist external image domains in your configuration to prevent unauthorized use of your infrastructure.
Remember: Image optimization is not about making images “look better,” but about delivering the smallest possible byte payload to the browser while maintaining visual fidelity. By trusting Vercel to handle the resizing, format conversion, and caching at the Edge, you solve the performance bottlenecks of heavy media without the manual overhead of traditional image pipelines.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!