configuring-image-optimization

Configure Next.js 16 image optimization with remotePatterns and security settings.

Updated Nov 21, 2025
One-click install
npx skills add https://github.com/djankies/claude-configs --skill configuring-image-optimization
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: configuring-image-optimization
Source: https://github.com/djankies/claude-configs/tree/main/nextjs-16/skills/configuring-image-optimization
Command: npx skills add https://github.com/djankies/claude-configs --skill configuring-image-optimization

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Image optimization changes in Next.js 16, including remotePatterns, AVIF defaults, and SVG handling, require updated configuration patterns and security considerations.

Core Features & Use Cases

  • Updated remotePatterns, deviceSizes, and imageSizes for modern devices and performance.
  • Security considerations for SVGs (dangerouslyAllowSVG, CSP, and contentDispositionType).
  • Migration guidance for configuration changes and performance tuning.

Quick Start

Update Next.js image optimization config to reflect new defaults and patterns; validate SVG security settings and cache behavior.

Frequently Asked Questions about configuring-image-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure image optimization in Next.js 16 with remote domains?

Image optimization in Next.js 16 requires migrating from the legacy domains array to remotePatterns, which provides granular control over allowed image sources. Set remotePatterns in next.config.js to specify protocol, hostname, and pathname rules for external images, ensuring only trusted domains can be optimized.

What security settings should I enable for SVG images in Next.js?

SVG security in Next.js involves three controls: set dangerouslyAllowSVG to true to permit SVG optimization, configure contentDispositionType to attachment for download safety, and define contentSecurityPolicy headers to restrict SVG execution. These prevent XSS attacks while allowing SVG delivery.

How do I migrate from domains to remotePatterns in Next.js image config?

Replace the domains array with remotePatterns, converting each domain into an object specifying protocol (http or https), hostname (with optional wildcards), and pathname patterns. This migration enforces explicit security parameters and supports multi-environment deployment across development and production.

Can I adjust default image sizes and formats for different devices in Next.js?

Yes, customize deviceSizes and imageSizes arrays in next.config.js to match your target devices and breakpoints. You can also set default formats (including AVIF) and configure minimumCacheTTL to control optimization caching behavior across environments.

What's the difference between remotePatterns and localPatterns in Next.js image optimization?

remotePatterns govern external image URLs from specified domains using protocol and hostname matching, while localPatterns control local image imports and public directory images. Both use pattern-based rules to enforce source validation and security policies.

Why does Next.js 16 require explicit configuration for AVIF image format?

AVIF is now a default format in Next.js 16 for better compression, but explicit format configuration lets you control fallback chains, device-specific formats, and browser compatibility. Configure formats in next.config.js to optimize delivery based on client capabilities and performance requirements.