In a catalog, a photo takes up a small area, but the browser downloads the original, which is several thousand pixels wide. This is barely noticeable on a fast connection, but dozens of cards create unnecessary data transfers. Account for screen density: to keep an image sharp, the file sometimes needs to be twice as wide as the display area. Look for excess size only after making this comparison.
Suppose the photo is 280 pixels wide in the card. On a screen with a density of 2x, it will usually need a source about 560 pixels wide. Check the display area, the selected file, and its size: an original 2400 pixels wide may load without benefiting this card.
Measure the photo's display area
Repeat the measurement on a phone and a wide screen. The number of card columns may change, and the photo may take up almost the full width in the mobile layout. A single fixed size chosen for the desktop layout can produce an image that is too small on a narrow screen with one column.
Check the cropping rules. With object-fit: cover, part of the frame is hidden, but the original is still downloaded. That does not make the excess area free. When reducing the size, preserve important product details. If you need a different crop, check it separately: changing the width should not silently crop the item.
Account for screen density
For a display area 280 wide and a density of 2, prepare a close match, such as 640 pixels. This leaves a small margin for sharpness. Assess the 2400-pixel original separately: does the card need it, or is it only for the enlarged view?
Check the actual file served by the selected URL. The name small.jpg does not prove that the dimensions are small, and the width=600 parameter does not guarantee that the image service applied it. Record the dimensions of the decoded image and make sure the URL does not return the unchanged original.
Select an image in the inspector:
Select the photo in the Elements tab and run this in the browser console to compare the display area with the selected file:
({ ширинаБлока: $0.getBoundingClientRect().width, плотность: devicePixelRatio, файл: $0.currentSrc, sizes: $0.sizes });For a block of 280 CSS px at a density of 2, the target is about 560 pixels. Open the selected file and check its dimensions; also check the transferred bytes in Network with the cache disabled.
Compare transfer size and quality
Compare the selected file under three conditions:
| Screen | Display area width | Density | File | What to check |
|---|---|---|---|---|
| Desktop catalog | 280 CSS px | 1 | 2400 px original | Is a source this large necessary? |
| Same catalog | 280 CSS px | 2 | 640 px variant | Quality and reasonable margin |
| Phone, one column | 350 CSS px | 2 | 320 px variant | Has sharpness been preserved? |
Compare the same product and crop. If the new file has different content or is significantly lower in quality, reducing the bytes does not by itself prove that the optimization worked. In a catalog, it is important to preserve the ability to distinguish the product's details, color, and shape.
Configure srcset and sizes to match the layout
The sizes attribute describes the image's width in the layout. Account for the container, padding, and the width at which the number of columns changes. For example, if the block on a phone is the screen width minus two 16-pixel margins, and after 600 pixels the layout switches to 280, the markup could look like this:
<img src="/images/lamp-640.webp"
srcset="/images/lamp-320.webp 320w, /images/lamp-640.webp 640w, /images/lamp-960.webp 960w"
sizes="(max-width: 600px) calc(100vw - 32px), 280px"
width="640" height="640" alt="Чёрный светильник L-24">All three files should show the same square photo at the specified widths. Replace the paths and sizes condition with values that match the card's actual CSS. After reloading, compare currentSrc and the transferred bytes at the same screen density and width.
Descriptions of the attributes and element behavior are available in the MDN documentation for img. Use it during implementation, but verify the result in the browser. The presence of srcset in the HTML alone does not prove that the set of sizes is useful for your catalog.
Keep the original for the gallery
Check the thumbnail generator for new and existing records. A change to a CMS setting sometimes affects only future uploads, while existing products continue to use the old files. Decide whether regeneration is needed, how it will be done, and how the originals will be preserved.
Assess compression and resizing separately. A new format does not fix an incorrect card image size, and a smaller width does not guarantee that details will be transferred well. The process for preparing image variants is covered in the image resizing guide, and ways to reduce file size are covered in the image compression guide.
Repeat the test under the same conditions
Check the first visible row of cards and the items further down the page. Request timing may differ because of lazy loading, but that does not explain why an oversized file was selected. If the image is already above the fold, assess the delay before it is discovered and loaded separately.
If one variant fails, check the fallback source. The new set of sizes should not result in a broken photo on another device. Include a product with a portrait photo and one with fine details in your sample: the same quality setting can produce different results in practice.
Check the savings and product details
At the same screen width and density, the browser selects a suitable variant instead of the huge original. The photo remains sharp, with its color and details preserved. The original is available separately for a larger view, and switching variants does not show a different photo.
Read also: Image resizing, Image compression, Technical page audit.