Claude-skill-registry configuring-image-optimization
Teach image optimization configuration changes in Next.js 16. Use when configuring images, troubleshooting image loading, or migrating image settings.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/configuring-image-optimization" ~/.claude/skills/majiayu000-claude-skill-registry-configuring-image-optimization && rm -rf "$T"
skills/data/configuring-image-optimization/SKILL.mdImage Optimization Configuration in Next.js 16
Breaking Changes
1. Removed Configuration Options
(removed)domains
- Replaced by
remotePatterns - More secure with pattern matching instead of wildcard domain access
(removed for 'default')loader
- Custom loaders must now be specified explicitly
- No implicit fallback to default loader behavior
array changesformats
- AVIF format now enabled by default
- Order affects format preference during negotiation
2. Changed Default Values
minimumCacheTTL
- Old default: 60 seconds
- New default: 31536000 seconds (1 year)
- Requires manual override for shorter cache durations
deviceSizes
- Updated default breakpoints to match modern devices
- Old:
[640, 750, 828, 1080, 1200, 1920, 2048, 3840] - New:
[640, 750, 828, 1080, 1200, 1920, 2048, 3840, 4096]
imageSizes
- Updated for modern layout shifts
- Old:
[16, 32, 48, 64, 96, 128, 256, 384] - New:
[16, 32, 48, 64, 96, 128, 256, 384, 512]
3. Security Enhancements
dangerouslyAllowSVG
- Now requires explicit
settingcontentDispositionType - Default changed to 'attachment' for security
- Inline SVG rendering requires opt-in configuration
unoptimized
- Stricter enforcement in production
- Warning logs for unoptimized images in development
- Performance metrics now track optimization bypass
Core Configuration
Basic Setup
module.exports = { images: { remotePatterns: [ { protocol: 'https', hostname: 'example.com', port: '', pathname: '/images/**', }, ], deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840], imageSizes: [16, 32, 48, 64, 96, 128, 256, 384], formats: ['image/webp', 'image/avif'], minimumCacheTTL: 31536000, }, }
remotePatterns
Securely allow external image sources:
module.exports = { images: { remotePatterns: [ { protocol: 'https', hostname: 'cdn.example.com', pathname: '/media/**', }, { protocol: 'https', hostname: '*.cloudinary.com', pathname: '/**', }, ], }, }
Pattern properties:
: 'http' or 'https'protocol
: exact match or wildcard (*.example.com)hostname
: specific port number (optional)port
: glob patterns using ** for nested pathspathname
minimumCacheTTL
Controls optimized image cache duration:
module.exports = { images: { minimumCacheTTL: 60, }, }
Common values:
: Frequently changing images60
: Hourly updates (1 hour)3600
: Daily updates (1 day)86400
: Static assets (1 year, default)31536000
imageSizes
Sizes for images with explicit
sizes prop:
module.exports = { images: { imageSizes: [16, 32, 48, 64, 96, 128, 256, 384], }, }
Usage:
<Image src="/avatar.jpg" sizes="(max-width: 768px) 64px, 128px" width={128} height={128} alt="Avatar" />
deviceSizes
Viewport breakpoints for responsive images:
module.exports = { images: { deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840], }, }
Usage:
<Image src="/hero.jpg" fill sizes="100vw" alt="Hero" />
localPatterns
Control local file optimization access:
module.exports = { images: { localPatterns: [ { pathname: '/public/uploads/**', search: '', }, ], }, }
Migration Patterns
From domains to remotePatterns
Before:
module.exports = { images: { domains: ['example.com', 'cdn.example.com'], }, }
After:
module.exports = { images: { remotePatterns: [ { protocol: 'https', hostname: 'example.com', pathname: '/**', }, { protocol: 'https', hostname: 'cdn.example.com', pathname: '/**', }, ], }, }
Adjusting Cache for Dynamic Content
Before (60s default):
module.exports = { images: { domains: ['api.example.com'], }, }
After (explicit cache):
module.exports = { images: { remotePatterns: [ { protocol: 'https', hostname: 'api.example.com', pathname: '/dynamic-images/**', }, ], minimumCacheTTL: 300, }, }
Restricting Image Sources
Before:
module.exports = { images: { domains: ['*.cloudinary.com'], }, }
After:
module.exports = { images: { remotePatterns: [ { protocol: 'https', hostname: 'res.cloudinary.com', pathname: '/my-account/image/upload/**', }, ], }, }
Common Configurations
Production
module.exports = { images: { remotePatterns: [ { protocol: 'https', hostname: 'cdn.production.com', pathname: '/**', }, ], formats: ['image/avif', 'image/webp'], minimumCacheTTL: 31536000, dangerouslyAllowSVG: false, }, }
Development
module.exports = { images: { remotePatterns: [ { protocol: 'http', hostname: 'localhost', port: '3001', pathname: '/**', }, ], minimumCacheTTL: 60, }, }
Multi-Environment
const isProd = process.env.NODE_ENV === 'production' module.exports = { images: { remotePatterns: isProd ? [ { protocol: 'https', hostname: 'cdn.production.com', pathname: '/**', }, ] : [ { protocol: 'http', hostname: 'localhost', port: '3001', pathname: '/**', }, ], minimumCacheTTL: isProd ? 31536000 : 60, }, }
Mobile-Optimized
module.exports = { images: { deviceSizes: [375, 414, 640, 750, 828, 1080], imageSizes: [24, 32, 48, 64, 96], }, }
SVG Support
module.exports = { images: { dangerouslyAllowSVG: true, contentDispositionType: 'inline', contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;", }, }
Quick Troubleshooting
Image Not Loading
Check pattern matches URL:
remotePatterns: [ { protocol: 'https', hostname: 'example.com', pathname: '/images/**', }, ]
Verify:
- Protocol matches (https vs http)
- Hostname exact or wildcard match
- Pathname pattern includes image path
Cache Not Updating
Override default TTL:
module.exports = { images: { minimumCacheTTL: 3600, }, }
Clear build cache:
rm -rf .next npm run build
SVG Not Rendering
Enable with security:
module.exports = { images: { dangerouslyAllowSVG: true, contentDispositionType: 'inline', contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;", }, }
Performance Issues
Reduce size variants:
module.exports = { images: { deviceSizes: [640, 828, 1200, 1920], imageSizes: [32, 64, 128, 256], }, }
Detailed References
For comprehensive examples and advanced configurations, see the
references/ directory:
configuration-examples.md
- Complete configuration patterns
- E-commerce, CMS, social media setups
- Multi-CDN configurations
- Industry-specific examples
security-settings.md
- SVG security best practices
- Content Security Policy options
- Content Disposition configurations
- Security monitoring strategies
troubleshooting.md
- Advanced debugging techniques
- Edge cases and solutions
- Performance optimization
- Runtime error resolution
migration-guide.md
- Step-by-step migration from Next.js 15
- Complex migration scenarios
- Verification checklist
- Rollback strategies
Related Skills
- Use
skill for Next.js Image component usageimages-component - Use
skill for responsive image patternsimages-responsive - Use
skill for custom image loader configurationimages-loaders