Teach image optimization configuration changes in Next.js 16. Use when configuring images, troubleshooting image loading, or migrating image settings.
Teaches Next.js 16 image optimization configuration changes. Use when configuring images, troubleshooting loading issues, or migrating from older versions with updated remotePatterns, cache settings, and security options.
/plugin marketplace add djankies/claude-configs/plugin install nextjs-16@claude-configsThis skill is limited to using the following tools:
references/configuration-examples.mdreferences/migration-guide.mdreferences/security-settings.mdreferences/troubleshooting.mddomains (removed)
remotePatternsloader (removed for 'default')
formats array changes
minimumCacheTTL
deviceSizes
[640, 750, 828, 1080, 1200, 1920, 2048, 3840][640, 750, 828, 1080, 1200, 1920, 2048, 3840, 4096]imageSizes
[16, 32, 48, 64, 96, 128, 256, 384][16, 32, 48, 64, 96, 128, 256, 384, 512]dangerouslyAllowSVG
contentDispositionType settingunoptimized
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,
},
}
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:
protocol: 'http' or 'https'hostname: exact match or wildcard (*.example.com)port: specific port number (optional)pathname: glob patterns using ** for nested pathsControls optimized image cache duration:
module.exports = {
images: {
minimumCacheTTL: 60,
},
}
Common values:
60: Frequently changing images3600: Hourly updates (1 hour)86400: Daily updates (1 day)31536000: Static assets (1 year, default)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"
/>
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"
/>
Control local file optimization access:
module.exports = {
images: {
localPatterns: [
{
pathname: '/public/uploads/**',
search: '',
},
],
},
}
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: '/**',
},
],
},
}
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,
},
}
Before:
module.exports = {
images: {
domains: ['*.cloudinary.com'],
},
}
After:
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'res.cloudinary.com',
pathname: '/my-account/image/upload/**',
},
],
},
}
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'cdn.production.com',
pathname: '/**',
},
],
formats: ['image/avif', 'image/webp'],
minimumCacheTTL: 31536000,
dangerouslyAllowSVG: false,
},
}
module.exports = {
images: {
remotePatterns: [
{
protocol: 'http',
hostname: 'localhost',
port: '3001',
pathname: '/**',
},
],
minimumCacheTTL: 60,
},
}
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,
},
}
module.exports = {
images: {
deviceSizes: [375, 414, 640, 750, 828, 1080],
imageSizes: [24, 32, 48, 64, 96],
},
}
module.exports = {
images: {
dangerouslyAllowSVG: true,
contentDispositionType: 'inline',
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
},
}
Check pattern matches URL:
remotePatterns: [
{
protocol: 'https',
hostname: 'example.com',
pathname: '/images/**',
},
]
Verify:
Override default TTL:
module.exports = {
images: {
minimumCacheTTL: 3600,
},
}
Clear build cache:
rm -rf .next
npm run build
Enable with security:
module.exports = {
images: {
dangerouslyAllowSVG: true,
contentDispositionType: 'inline',
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
},
}
Reduce size variants:
module.exports = {
images: {
deviceSizes: [640, 828, 1200, 1920],
imageSizes: [32, 64, 128, 256],
},
}
For comprehensive examples and advanced configurations, see the references/ directory:
configuration-examples.md
security-settings.md
troubleshooting.md
migration-guide.md
images-component skill for Next.js Image component usageimages-responsive skill for responsive image patternsimages-loaders skill for custom image loader configurationMaster authentication and authorization patterns including JWT, OAuth2, session management, and RBAC to build secure, scalable access control systems. Use when implementing auth systems, securing APIs, or debugging security issues.