Next.js Image Optimization Cache Not Working
Next.js Image component caching isn't working properly. Updated images still show old versions, or image optimization isn't triggered when source images change. Users see stale content.
Image caching issues occur when cache headers aren't properly configured, image paths change unexpectedly, or Vercel's Image Optimization API cache isn't invalidated.
Error Messages You Might See
Common Causes
- Using query parameters in image URLs without stable naming (changing URLs prevent caching)
- Cache-Control headers set to no-cache or very short expiry for optimized images
- Image filename/path changes but URL remains same, serving stale cached version
- Dynamic image URLs (different URL for same image) preventing cache hit
- Vercel Image Optimization cache not automatically invalidating on deployment
How to Fix It
Use stable URLs: Keep image URLs consistent. If image content changes, include hash in filename: avatar-abc123.jpg
Configure cache headers: In next.config.js, set long cache for optimized images:headers: async () => [{ source: '/assets/**', headers: [{ key: 'Cache-Control', value: 'public, max-age=31536000, immutable' }] }]
Use Image version parameter: In development, append query string: <Image src={url + '?v=' + Date.now()} /> to bust cache.
Deploy to invalidate: Vercel automatically invalidates image cache on new deployment.
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
How long should images be cached?
For static images: max-age=1 year (31536000 seconds). For dynamic avatars: max-age=1 day or use version query param.
Why is my updated image still showing old version?
URL is cached. Change filename or add ?v=timestamp to force cache bust. Next.js Image caches based on URL.
Does Vercel Image Optimization cost extra?
Free tier: 1000 optimizations/month. Paid: $0.15 per 10,000 additional. Caching reduces cost.