WEB-38Recommended
Send small, modern images
Send AVIF or WebP images, each one sized for the screen it lands on with srcset and sizes, and always give width and height.
How to do it
Export AVIF, WebP and JPEG at several widths. Serve them with <picture>, srcset and an honest sizes. Add a media source when phones should get a smaller file than srcset would pick for sharp screens. Always set width and height. SVG icons and logos scale without loss, so they need no srcset.
Examples
HTML example
<picture>
<source media="(max-width: 600px)" type="image/avif" srcset="/assets/hero-768-f0c7bcf5bb.avif">
<source type="image/avif" srcset="/assets/hero-768-f0c7bcf5bb.avif 768w, /hero-1536.avif 1536w" sizes="(max-width: 1200px) 100vw, 1200px">
<source type="image/webp" srcset="/assets/hero-768-e9008a232a.webp 768w, /hero-1536.webp 1536w" sizes="(max-width: 1200px) 100vw, 1200px">
<img src="/hero-1536.jpg" width="1536" height="1024" alt="Team at work">
</picture>
How to check
Lighthouse image-delivery-insight passes (it replaced the separate image audits in Lighthouse 13). A browser test at 360 and 1280 px downloads one copy of each image. None is wider than twice its displayed width.
Measured
On a reference site, JPEG only (no AVIF, WebP or srcset) cost 0.45 s of mobile LCP and 73 KB. One large image for every screen cost 0.15 s. In an earlier lab, serving phones a 768 px AVIF through a media source showed the hero 100 ms sooner on 3× phones.
Sources
Related rules
- WEB-39 Load far-down images later in Website
- SEO-65 Name image files for what they show in SEO
- MED-45 Rebuild every uploaded image in Files and media
- MED-7 Make image sizes from a fixed list in Files and media
- MED-10 Pick the image format from Accept and send Vary in Files and media
- MED-11 Store each image's width and height in Files and media
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/website/performance/image-optimization">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.