A typical shop shows the same product photograph in at least five places: a square thumbnail in the category grid, a wider card in search results, the large image on the product page, a zoom view, and a small picture in the basket and the order confirmation email. Then there are phones, tablets, laptops and 4K monitors, each wanting a different number of pixels for the same slot. Exporting every one of those by hand, or in a build step, gives you a folder of files nobody can keep track of. And as soon as a designer changes the grid from four columns to three, every one of them is the wrong size.
The approach that scales is to keep one original per photograph, at the best resolution you have, and let the edge produce each rendition the first time a browser asks for it. This article walks through how that works for a catalogue, and the handful of decisions that make the difference between a fast shop and a slow one.
One original, every size from a URL
Your originals stay where they are: on your own server, in a bucket, or in the media folder of your shop platform. The account's origin points at that location, and the delivery URL names the file and what you want done to it:
https://a3f9c21b.zwcld.net/v1/products/trail-shoe.jpg?w=400&h=400&fit=cover
https://a3f9c21b.zwcld.net/v1/products/trail-shoe.jpg?w=1200&q=auto
https://a3f9c21b.zwcld.net/v1/products/trail-shoe.jpg?w=2400&q=auto
The first request for each URL fetches the original once, resizes it, encodes it and caches the result. Every later request is a cache hit. The hostname identifies your account, so the URL carries no API key and is safe to put straight into a product template.
The format is left to the edge on purpose. With no f in the URL, the default is
f=auto: the node reads the browser's Accept header and sends AVIF
where it is supported, WebP where that is, and the original format otherwise. The response
carries Vary: Accept, so a shared cache never serves an AVIF to a browser that
cannot decode it. You do not need a <picture> element with three
<source> tags. We cover why in
AVIF, WebP, JPEG: let the browser
decide.
Squares from photos that are not square
Category grids are usually square, while product photographs are usually portrait or
landscape. fit=cover fills the box and crops the overflow, and by default it
crops around the centre. For a shoe photographed side-on that is fine. For a tall bottle
against a lot of empty studio background, or a model standing to one side of the frame, the
centre is often the wrong place.
There are three ways to move the crop, in order of how much work they take:
-
fp=x,ysets the focal point by hand, as two numbers from 0 to 1 on the original.fp=0.5,0.3keeps the upper middle. It costs nothing at request time, and it suits a hero product photographed once and shown everywhere. -
trim=truecuts away a border of near-uniform colour before resizing, which removes the white studio background around a packshot. The product then fills the square instead of floating in the middle of it.trimtolcontrols how far a pixel may differ from the border and still be trimmed. -
ai_crop=truefinds the subject with a saliency model and crops around it. It is the answer for a catalogue of thousands of photos where nobody will set a focal point on each one. See Smart crop: the middle is usually wrong.
When the opposite is wanted (the whole product, never cropped, on a uniform tile),
fit=pad with bg letterboxes the image to exactly the requested box
in your background colour:
/v1/products/lamp.png?w=600&h=600&fit=pad&bg=f5f5f4
That gives a grid of identical tiles from originals of any shape, which is what most marketplace-style listings want.
Name the sizes your theme uses
Writing w=400&h=400&fit=cover&q=75 into five templates means five
places to change when the design changes. A named preset, defined once on the
console's Presets tab, turns it into a word. A preset holds a width, a height, a fit mode, a
format, a quality and optionally a text watermark:
/v1/products/trail-shoe.jpg?preset=grid
/v1/products/trail-shoe.jpg?preset=pdp
/v1/products/trail-shoe.jpg?preset=zoom
A preset expands into ordinary parameters before anything else happens, so it is the same
rendition and the same cache entry as the long form. An explicit parameter in the URL always
wins over the preset, so ?preset=pdp&w=800 is the product-page preset at
800 pixels.
Once the theme uses presets, you can lock the account down. Presets only, on
the Limits tab, refuses any transformation parameter that is not a preset name. That includes
fp, trim, q=auto and ai_crop, so it suits a
shop whose every image slot is a preset. If your templates use those parameters,
permitted output sizes is the better fit: it lists the widths you publish,
allows any other parameter, and refuses unlisted sizes with a 400. Either one
stops a crawler or a curious visitor from requesting
w=4999, w=4998 and so on, each of which would otherwise be its own
origin fetch, encode and cache entry charged to your account. Why that matters is in
Cache keys multiply faster than you
think.
srcset: let the browser pick the width
The product page image is a few hundred pixels wide on a phone and over a thousand on a desktop, and on a high-density screen it needs two or three times that. The browser knows which. Give it a list of candidates and tell it how wide the slot is:
<img
src="https://a3f9c21b.zwcld.net/v1/products/trail-shoe.jpg?w=800&q=auto"
srcset="https://a3f9c21b.zwcld.net/v1/products/trail-shoe.jpg?w=400&q=auto 400w,
https://a3f9c21b.zwcld.net/v1/products/trail-shoe.jpg?w=800&q=auto 800w,
https://a3f9c21b.zwcld.net/v1/products/trail-shoe.jpg?w=1200&q=auto 1200w,
https://a3f9c21b.zwcld.net/v1/products/trail-shoe.jpg?w=1600&q=auto 1600w"
sizes="(min-width: 1024px) 50vw, 100vw"
width="1600" height="1600"
alt="Trail running shoe, side view, in blue">
Four or five widths are enough. Each one you add is another rendition per product that has
to be generated and cached, and the difference between 1100 and 1200 pixels is not one a
shopper sees. Responsive
images: the widths you actually need shows the arithmetic. The width and
height attributes reserve the space before the image arrives, so the price and
the Add to basket button do not jump down the page while it loads.
Quality per image, not per site
A catalogue mixes flat illustrations, products on white, and detailed lifestyle photographs.
One fixed quality is too high for the first and sometimes too low for the last.
q=auto encodes, measures the result against the rendition with DSSIM (a measure
of how different the image looks rather than how many pixels changed), and delivers the
lowest quality that still looks the same. The search costs a few extra encodes on the first
request, and nothing after that, because the result is cached like any other rendition.
Colours that match the product
Returns cost more than bandwidth. A jumper that looks teal on the product page and arrives green is a returned jumper. Photographs from modern cameras and phones are often in a wide colour space such as Display P3 or Adobe RGB. Stripping the colour profile without converting the pixels (which some image pipelines do to save a few kilobytes) makes those colours come out dull and shifted.
The edge strips metadata by default, but it converts the pixels to sRGB first, so the colours you see in the delivered image are the colours of the original. Stripping also removes EXIF data such as camera serial numbers and GPS coordinates, which a product shot taken in someone's home should not be publishing. See The metadata you did not mean to publish.
When a photograph changes
When a product is re-shot, the new file goes to the same path, and the cached renditions of the old one need to go. A purge by path removes the object and every transformation of it in one call, so you never have to list which sizes were served:
curl -X POST https://console.zawcloud.io/api/v1/purges \
-H "Authorization: Bearer $ZAWCLOUD_TOKEN" \
-H "Content-Type: application/json" \
-d '{"target": "/v1/products/trail-shoe.jpg"}'
A management token with only the purge scope is enough, which makes it safe to
call from a product-import job or a CMS save hook. A prefix such as
/v1/products/* clears a whole folder after a bulk re-shoot.
What you end up with
- One original per photograph, in the storage you already use.
- A few presets that describe your theme, changeable without a deploy.
- AVIF or WebP for every browser that supports them, without template changes.
- Each image delivered at the smallest quality that still looks right, in correct colour.
- A fixed set of renditions that nobody outside can multiply.
Images are usually most of a product page's weight. In Images are most of your page weight we explain why that is where page-speed work should start. For a shop, a faster product page usually means more visitors who reach the basket.