Configuration
Client Provider Options
When registering provideImageOptimizerLoader, you can pass an optional configuration object:
routePrefix
The path where the image optimizer middleware is mounted. Default is /_ng/image.
defaultWidth
The default width used if NgOptimizedImage doesn't provide one. Default is 1080.
defaultQuality
The default image quality (1-100). Default is 90.
Server Middleware Options
The imageOptimizerHandler accepts an optional configuration object that implements the ImageConfig interface.
deviceSizes
Allowed widths for device breakpoints. Used to validate requested widths. Default is [640, 750, 828, 1080, 1200, 1920, 2048].
imageSizes
Allowed widths for smaller UI elements. Used to validate requested widths. Default is [16, 32, 48, 64, 96, 128, 256, 384].
remotePatterns
An array of objects to configure which external domains you allow the optimizer to fetch images from. This is crucial for security to prevent your server from acting as an open proxy.
import { imageOptimizerHandler } from 'ng-image-optimizer/server';
app.get('/_ng/image', imageOptimizerHandler(browserDistFolder, {
remotePatterns: [
{
protocol: 'https',
hostname: 'example.com',
pathname: '/images/**',
},
],
}));localPatterns
An array of objects to configure which local paths you allow the optimizer to process. Leave empty to allow all local paths (default behavior inside browserDistFolder).
minimumCacheTTL
The minimum time in seconds that an image should be cached before re-optimizing. Default is 14400 (4 hours).
formats
An array of supported output formats. Currently supports ['image/webp'] and ['image/avif', 'image/webp']. Default is ['image/webp'].
dangerouslyAllowSVG
Whether to allow SVG images to be optimized. Default is false.
contentSecurityPolicy
The Content-Security-Policy header to set on image responses. Default restricts scripts and frames.
contentDispositionType
Whether the image should be rendered inline or downloaded as an attachment. Default is 'inline'.
maxCacheSize
The maximum size in bytes for the LRU memory cache index. Default is 52428800 (50MB).