Key takeaways
- Define a width ladder and round every request up to the nearest rung
- An uncapped responsive layout requests dozens of near-identical widths
- Only transform images you own, from an allowlisted source
- Never pass a user-supplied URL to the transformer
- Serve AVIF or WebP with a JPEG fallback, and vary the cache key correctly
- Watch the transformation quota, not just the invoice
Most ecommerce sites start with on-demand image transformation: the page asks for an image at a particular width, something resizes it, the result gets cached. It works well at a few hundred products.
At a few thousand products with several images each and a responsive layout requesting six widths, the same approach generates tens of thousands of transformations and an invoice nobody predicted.
Use a fixed width ladder
Do not let the page request arbitrary widths. Define a ladder, for example 320, 640, 960, 1280 and 1920, and round every request up to the nearest rung.
This single change usually cuts transformation counts by an order of magnitude, because a responsive layout left to itself will request 847px on one device and 851px on another and treat them as different images.
Cap what can be transformed
An open transformation endpoint is both a cost problem and a security one.
- Only transform images you own, from an allowlisted source
- Reject requests for widths outside the ladder rather than serving them
- Never pass a user-supplied URL to the transformer
That last point matters more than it sounds. An endpoint that fetches and resizes any URL is a server-side request forgery vector and a way for someone else to use your bandwidth.
Negotiate format properly
Serve AVIF or WebP where supported and fall back to JPEG where not. The saving is substantial and the implementation is well understood.
The thing to watch is the cache key: if the format varies by request header, the cache must vary on it too, or some visitors will receive a format their browser cannot display.
Decide where the work happens
- At upload. Generate the ladder once when the image is added. Predictable cost, slower uploads, storage for variants you may not use.
- On first request, then cached. Cost follows actual usage, with a slow first request.
- At build. Only viable when the catalogue is small and changes rarely.
For most catalogues, option two with a strict ladder and a long cache is the right balance.
Watch the quota, not just the bill
Transformation services usually have a rate limit as well as a price. Hitting the limit does not produce an error page people recognise: it produces images that fail to load, which looks like a broken site rather than a quota problem.
Frequently asked
Questions readers ask
How should I serve images on a large ecommerce catalogue?
Define a fixed ladder of widths, round requests up to the nearest rung, cache aggressively and negotiate format so modern browsers get AVIF or WebP. This usually cuts transformation counts by an order of magnitude.
Why did my images suddenly stop loading?
Check the transformation quota before assuming files are missing. Hitting a rate limit produces images that fail to load, which looks identical to a broken site in the browser and entirely different in the logs.
Is an open image resizing endpoint a security risk?
Yes. An endpoint that fetches and resizes any supplied URL is a server-side request forgery vector and lets someone else use your bandwidth. Restrict it to an allowlisted source and reject widths outside your ladder.





