How WebP images are delivered
When Use WebP images is enabled, the Google Page Speed Optimizer extension for Magento 2 creates a .webp copy of each image and changes the storefront to load that copy. This page explains where the WebP URL is used, where the original image remains as a fallback, and what happens when a copy does not exist yet.
1. Image URLs are replaced in place
For most images the extension replaces the original URL with the WebP URL. It does not wrap the image in a <picture> element, so the browser receives only the WebP URL and has no fallback to the original. All current browsers display WebP.
The URL is replaced in:
<img src="...">tags in the page HTML;- the product page gallery (thumbnail, main and full-size images);
- swatch images of configurable products;
- Page Builder background images;
- background images in inline
styleattributes and in<style>blocks of the page.
2. Where the original image stays as a fallback
If the theme already outputs a <picture> element, the extension keeps every original <source> and adds a WebP <source type="image/webp"> in front of it. A browser that cannot display WebP skips that source and uses the original one.
The extension adds this fallback only to <picture> markup that the theme already outputs. It does not create a <picture> element for an ordinary <img>.
3. Images without a WebP copy
- An image whose WebP copy has not been generated yet keeps its original URL. The page never points to a WebP file that does not exist.
- If a recorded WebP copy is missing from the media storage, the original URL is served and the image is queued to generate the copy again.
- The WebP copy is a separate file. The original image is kept and is not replaced by it.
The extension replaces URLs in the page HTML and in the gallery and swatch data listed above. An image that a theme or another extension loads with JavaScript from data the extension does not process keeps its original URL.
To check which images have a WebP copy, see Ensure images are optimized. When Use AVIF images is also enabled, an AVIF copy is used in the same places and takes priority over WebP, see How to serve AVIF images.