Skip to main content

Dynamic Mode (Device-Aware Optimization)

About dynamic mode

What is it? Dynamic mode automatically adapts image quality, dimensions, and format based on the visitor's device type. Instead of serving the same image to every user, each device category (mobile, tablet, desktop, etc.) receives an optimized version defined by a preset.

Example: A 4K product image is served at 1920 px wide / quality 90 on desktop, but 800 px wide / quality 75 on mobile — automatically, without any URL changes.

Enable dynamic mode

Dynamic mode is included in the Image Optimizer service. Configure via environment variables:

DYNAMIC_MODE=true
PRESET_LIST='[{"device":"mobile","quality":75,"width":800},{"device":"tablet","quality":80,"width":1200},{"device":"pc","quality":90,"width":1920},{"device":"default","quality":80}]'
VariableTypeDefaultDescription
DYNAMIC_MODEbooleanfalseEnable device-aware preset matching
PRESET_LISTstring(none)JSON array of device presets (required when enabled)

When DYNAMIC_MODE is false (default), the system uses static defaults from QUALITY_PRESET, CONVERT_TO_WEBP, and other environment variables as before.

Device categories

The device type is detected automatically from the User-Agent header:

CategoryMatches
mobileSmartphones
tabletTablets
pcDesktop / laptop browsers
applianceSmart TVs, game consoles
defaultUnrecognized or missing UA

Preset configuration

Each preset in PRESET_LIST is a JSON object with the following fields:

FieldTypeRequiredDescription
devicestringYesDevice category to match (see table above)
qualitynumber (1-100)NoImage quality for this device
widthnumberNoTarget image width in pixels
heightnumberNoTarget image height in pixels
webpbooleanNoOverride WebP conversion for this device

Fallback preset

If no preset matches the detected device, the system looks for a preset with device set to "default" or "default/fallback". If no fallback exists either, the static defaults from other environment variables are used.

Example preset list

[
  { "device": "mobile",  "quality": 75, "width": 800, "webp": true },
  { "device": "tablet",  "quality": 80, "width": 1200 },
  { "device": "pc",      "quality": 90, "width": 1920 },
  { "device": "appliance", "quality": 70, "width": 1280 },
  { "device": "default", "quality": 80 }
]

Query parameter overrides

Query parameters (?width=, ?height=, ?quality=, ?fmt=, ?crop=) always take priority over preset values. This allows per-image fine-tuning on top of device-aware defaults.

# Preset sets width=800 for mobile, but this URL forces 400
https://cdn.example.com/photo.jpg?width=400

Usage examples

# Automatic: mobile gets 800px/q75, desktop gets 1920px/q90
https://cdn.example.com/photo.jpg

# Override quality regardless of device preset
https://cdn.example.com/photo.jpg?quality=60

# Override width + add crop regardless of device preset
https://cdn.example.com/photo.jpg?width=600&crop=1:1