This guide routes product images from commercetools through Akamai Image and Video Manager (IVM), which converts the format, resizes per breakpoint and sets the quality. It also covers responsive srcset and sizes, along with dashboards that catch heavy images per market, and is written for frontend engineers and tech leads of commerce sites. The examples use @commercetools/platform-sdk 9.8.0, Next.js 16.4.6, lighthouse 13.6.0, chrome-launcher 1.2.3, @datadog/datadog-api-client 1.64.0 and @datadog/browser-rum 7.19.0. These are the current npm versions on 1 December 2026.
Product images in commercetools
In commercetools, each product variant has an images array, where each Image has a url, the dimensions of the original image (w and h) and an optional label.
import type { Image, ProductProjection } from '@commercetools/platform-sdk'
function firstImage(product: ProductProjection): Image | undefined {
return product.masterVariant.images?.[0]
}
The url points to the image in its original size. If you upload images through the API or the Merchant Center, commercetools stores them on its own CDN, and it accepts JPEG, PNG and GIF files of up to 10 MB.
The commercetools CDN also serves fixed sizes when you add a suffix before the file extension: -thumb (50 x 50), -small (150 x 150), -medium (400 x 400), -large (700 x 700) or -zoom (1400 x 1400). commercetools never scales an image up. These sizes also do not follow the breakpoints of your layout, and that is the gap an image CDN fills.
What Image and Video Manager does
IVM uses a few terms:
- The pristine image is the original that IVM fetches from your origin.
- A derivative image is a version that IVM creates from it, for example smaller or in another format.
- A policy holds the settings and transformations for derivatives, and a policy set groups policies. Akamai creates a default policy with each new policy set.
The image settings of a policy include:
- Quality type. You choose either a static quality from 1 to 100, with a system default of 85, or perceptual quality, with a minimum that IVM never goes below.
- Slow connection quality override. This sets a fixed, lower quality for users with a round-trip time of 300 ms or more, and IVM also uses it when the browser sends the
Save-Dataheader. - Derivative widths. These are the breakpoint widths, in pixels, that IVM creates.
IVM also converts images to modern formats such as WebP and AVIF when the browser supports them.
The first request for a new image gets a real-time derivative, which is fast but lower in quality and comes in one format, such as JPEG. IVM then creates an offline derivative in the background, with perceptual quality and more formats, and later requests get that offline version. That is why your first test of a new image can show a JPEG.
Route commercetools images through Akamai
This change has two parts, and each part often has its own owner.
The CDN configuration. Use a hostname for images, for example images.example.com, with the commercetools image host as origin. In Property Manager, add the Image and Video Manager (Images) rule, which matches requests on file extension and must be the last rule that changes origin settings. In the behavior of the rule, select the policy set and turn on automatic breakpoint selection and automatic file type conversion. Test the property on the Akamai staging network before you activate it in production.
The product data. Rewrite the image URLs once, in the layer that serves product data to the storefronts, so that every product image goes through IVM without changes in each component.
import type { Image, ProductProjection, ProductVariant } from '@commercetools/platform-sdk'
const IMAGE_HOST = 'https://images.example.com' // hostname with the IVM rule
function toCdnImage(image: Image): Image {
const original = new URL(image.url)
return { ...image, url: `${IMAGE_HOST}${original.pathname}` }
}
function withCdnImages(variant: ProductVariant): ProductVariant {
return { ...variant, images: variant.images?.map(toCdnImage) }
}
export function withCdnProductImages(product: ProductProjection): ProductProjection {
return {
...product,
masterVariant: withCdnImages(product.masterVariant),
variants: product.variants.map(withCdnImages),
}
}
This example keeps the path of the image, which works when the Akamai property passes the path unchanged to the commercetools image host.
Responsive images with imwidth
With automatic breakpoint selection, IVM chooses a width for each device, but you can also ask for a width with the imwidth query parameter. IVM then serves that width or the next larger width in the policy, so use the derivative widths of the policy as the widths in srcset.
const widths = [320, 640, 960, 1280] // the derivative widths of the policy
export function srcSet(url: string): string {
return widths.map((width) => `${url}?imwidth=${width} ${width}w`).join(', ')
}
The result in HTML looks like this:
<img
src="https://images.example.com/products/shoe.jpg?imwidth=640"
srcset="https://images.example.com/products/shoe.jpg?imwidth=320 320w,
https://images.example.com/products/shoe.jpg?imwidth=640 640w,
https://images.example.com/products/shoe.jpg?imwidth=960 960w,
https://images.example.com/products/shoe.jpg?imwidth=1280 1280w"
sizes="(min-width: 1024px) 25vw, 50vw"
width="1400"
height="1400"
loading="lazy"
alt="Running shoe, side view"
/>
sizes tells the browser how wide the image is in the layout: here, a tile is a quarter of the viewport on wide screens and half of it on smaller screens. The browser then picks the smallest file from srcset that fits. Take width and height from image.dimensions: the browser uses them for the aspect ratio and reserves space before the image loads, so the layout does not shift.
With next/image
In Next.js, a custom loader adds imwidth to every image URL, and you point loaderFile to it in next.config.ts:
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
images: {
loader: 'custom',
loaderFile: './lib/akamai-loader.js',
},
}
export default nextConfig
// lib/akamai-loader.js
'use client'
export default function akamaiLoader({ src, width }) {
const url = new URL(src)
url.searchParams.set('imwidth', String(width))
return url.href
}
Next.js also passes quality to the loader, but this loader ignores it because the IVM policy sets the quality.
import Image from 'next/image'
import type { Image as ProductImage } from '@commercetools/platform-sdk'
type Props = { image: ProductImage; alt: string; preload?: boolean }
export function ProductTileImage({ image, alt, preload = false }: Props) {
return (
<Image
src={image.url}
alt={alt}
width={image.dimensions.w}
height={image.dimensions.h}
sizes="(min-width: 1024px) 25vw, 50vw"
preload={preload}
/>
)
}
With sizes, Next.js generates a full srcset with width descriptors, while an image with a width but no sizes only gets a 1x and 2x srcset. Next.js takes the widths from deviceSizes and imageSizes, and the default deviceSizes are 640, 750, 828, 1080, 1200, 1920, 2048 and 3840. Add these widths to the IVM policy, or set deviceSizes and imageSizes to the widths of your policy. Use preload for the image that is the Largest Contentful Paint (in Next.js 16, preload replaces priority).
Check the response headers
Akamai documents a x-im-piez: on request header that adds IVM details to the response, and the Piez extension for Chrome shows the same details in the browser. With curl, the request looks like this:
curl -IXGET \
-H "x-im-piez: on" \
-H "Accept: image/avif, image/webp, image/png, image/jpeg, image/gif" \
"https://images.example.com/products/shoe.jpg?imwidth=640"
To get an AVIF image in a test, the Accept header must list every format of the AVIF group, as above, and wildcards such as image/* do not count. Check these response headers:
content-typeshows the format that IVM served.serverisAkamai Image Serverfor a real-time derivative andAkamai Image Managerfor an offline derivative.x-im-original-sizeis the size of the pristine image in bytes.x-im-result-widthis the width of the derivative in pixels.x-im-encoding-qualityis the quality that IVM used.
Catch heavy images per market
The route above covers images in product data, but other images, such as banners on a homepage, do not pass through it unless you route them too. A market can still publish a heavy image, so measure each market on a schedule to see it early.
Lighthouse per market, sent to Datadog
This script runs Lighthouse five times per page, takes the median run and sends three gauge metrics to Datadog. The Lighthouse docs say that the median of five runs is twice as stable as one run.
// report-markets.mjs
import lighthouse from 'lighthouse'
import { computeMedianRun } from 'lighthouse/core/lib/median-run.js'
import * as chromeLauncher from 'chrome-launcher'
import { client, v2 } from '@datadog/datadog-api-client'
const pages = [
{ market: 'market-a', page: 'plp', url: 'https://www.example.com/market-a/shoes' },
{ market: 'market-b', page: 'home', url: 'https://www.example.com/market-b/' },
]
const configuration = client.createConfiguration() // reads DD_API_KEY and DD_APP_KEY
configuration.setServerVariables({ site: 'datadoghq.eu' })
const metrics = new v2.MetricsApi(configuration)
const chrome = await chromeLauncher.launch({ chromeFlags: ['--headless'] })
const timestamp = Math.floor(Date.now() / 1000)
const series = []
for (const { market, page, url } of pages) {
const runs = []
for (let i = 0; i < 5; i++) {
const result = await lighthouse(url, { port: chrome.port, output: 'json', onlyCategories: ['performance'] })
runs.push(result.lhr)
}
const lhr = computeMedianRun(runs)
const requests = lhr.audits['network-requests'].details?.items ?? []
const images = requests.filter((item) => item.resourceType === 'Image')
const largestImage = Math.max(0, ...images.map((item) => item.transferSize ?? 0))
const tags = [`market:${market}`, `page:${page}`]
const gauge = (metric, value) => ({ metric, type: 3, points: [{ timestamp, value }], tags })
series.push(
gauge('lighthouse.performance.score', lhr.categories.performance.score * 100),
gauge('lighthouse.total_byte_weight', lhr.audits['total-byte-weight'].numericValue),
gauge('lighthouse.largest_image_bytes', largestImage),
)
}
chrome.kill()
await metrics.submitMetrics({ body: { series } })
type: 3is the gauge type in the metrics API.total-byte-weightis the total transfer size of the page in bytes.- The
network-requestsaudit lists every request, with itsresourceTypeandtransferSize. - The
image-delivery-insightaudit lists images that could be smaller, with thewastedBytesper image, so you can use it in the report to show which file to fix.
Run the script on a schedule in your CI, and add a version tag with the storefront release so that a drop in the score lines up with a release.
Dashboards and scheduled reports
Build a dashboard in Datadog with a template variable for market, and show the performance score, the total byte weight and the largest image per page over time.
To send it as a report, open the dashboard, click Share and choose Schedule report. Datadog then sends the dashboard as a PDF to email addresses, Slack channels or Microsoft Teams channels, on the schedule and for the time frame that you set. With Edit Variables, you set the template variables per report, so each market can get its own report.
Images that real users load
Lighthouse tests a few pages from one place, while RUM shows the images that real users load. In @datadog/browser-rum 7.19, trackResources is on by default, so each image becomes a resource event with resource.type, resource.url and resource.size. Add the market to every event:
import { datadogRum } from '@datadog/browser-rum'
datadogRum.setGlobalContextProperty('market', 'market-a')
Then search the RUM Explorer for large images, for example @resource.type:image @resource.size:>1000000, and group the results by market. The Datadog RUM guide for the Next.js App Router covers the setup of the SDK.
The image hostname is a different origin from the storefront, and Datadog needs the Timing-Allow-Origin response header to collect detailed timings for cross-origin resources. Without it, the browser returns 0 for many timing values of those resources, so ask for this header on the image hostname.
Alternatives
Akamai is one option, but other CDNs and image services also offer image APIs with parameters for width, format and quality. The Next.js docs include example loaders for AWS CloudFront, Cloudinary, Cloudflare, Fastly, imgix and others. Without a custom loader, Next.js optimises images on your own server through /_next/image. Either way, the steps stay the same: route product image URLs through one image service, align the widths with srcset, and measure per market.
In practice
A multi-brand consumer goods company that sells direct to consumers had low performance scores across markets, with product images from commercetools and storefronts running behind Akamai. The case study describes the wider project.
In June 2023, we worked with the DevOps and backend teams to pass all images in the product data automatically through the image optimisation API of Akamai. The DevOps team set up the Akamai routing for the commercetools images. Because the change sat in the product data of the backend, every product image got the new URL without changes per component. On the product listing page of one market, the payload went from 3.5 MB to 567 KB.
We wrote the performance reports, which ran automatically from June 2022. Performance dashboards for each market in Datadog, with a monthly report, showed problems per market. They revealed that one market had put a 5 MB image on its homepage, and they also caught a storefront release that lowered the performance score by two points.
Checklist
- Check the format, file size and dimensions of the
imagesof your product variants. - Create an IVM policy with derivative widths that match your layouts.
- Choose static or perceptual quality, and a lower quality for slow connections.
- Add the Image and Video Manager (Images) rule as the last rule that changes origin settings.
- Test the property on the Akamai staging network first.
- Rewrite product image URLs once, in the layer that serves product data.
- Use the policy widths as
imwidthvalues insrcset. - Set
sizes,widthandheighton every product image. - In Next.js, use a custom loader, set
sizesand usepreloadfor the LCP image. - Check the response headers with
x-im-piez: onand a fullAcceptheader. - Send Lighthouse results per market and page to Datadog.
- Add
Timing-Allow-Originto the image hostname for RUM. - Schedule a dashboard report per market.
To have your images and page weight reviewed, see the web performance audit. To have your performance monitoring per market reviewed, see the frontend observability assessment or contact us.
Sources
- commercetools: Products API, Image
- commercetools: Upload Product image
- npm: @commercetools/platform-sdk
- Akamai: Key concepts and terms
- Akamai: Create and edit policies
- Akamai: Optimize images
- Akamai: Add the Image and Video Manager rule
- Akamai: Add the image behavior
- Akamai: Select a specific derivative
- Akamai: Optimization details in Piez
- Akamai: Test on staging
- Akamai: Supported image and video formats
- Next.js: Image component
- Next.js: images configuration
- MDN: Responsive images
- MDN: The img element
- MDN: Resource timing
- Lighthouse: Using Lighthouse programmatically
- Lighthouse: Score variability
- Datadog: Submit metrics API
- Datadog: RUM browser data collected
- Datadog: Monitoring resource performance
- Datadog: RUM browser advanced configuration
- Datadog: RUM search syntax
- Datadog: Scheduled reports