Image optimization audit
Goal: every image is sent at the size it is displayed (x device pixel ratio), in the best format the browser accepts, loaded at the right moment, with its space reserved. Convert copies, never overwrite originals.
Paths below are relative to this skill's folder (in Claude Code: ${CLAUDE_SKILL_DIR}).
When to use
- Lighthouse image audits (sizing, next-gen formats, encoding, offscreen images, image delivery)
- "Our pages are 5 MB", "convert our images to WebP/AVIF", "set up srcset"
- Before a launch or after a redesign that added large photography
When not to use
- The hero image specifically is slow to start (priority, discovery):
lcp-optimization - Image caching headers:
caching-headers-review - Layout jumps only:
cls-inp-diagnosis
Workflow
- Collect inputs. The page HTML, and a HAR for real byte counts: DevTools > Network >
reload with "Disable cache" > right-click > "Save all as HAR" (use the sanitized export
if offered; HAR files can contain cookies, so do not commit or share them).
curl -sL https://example.com/ -o page.html - Run the audit (read-only):
python3 scripts/image_audit.py page.html page.har python3 scripts/image_audit.py page.html --eager-first 1 --lazy-after 3 --max-kb 150 --json--eager-first: images expected above the fold.--lazy-after: from which image on lazy-loading is expected. Adjust after looking at the page on a phone. - Prioritise by bytes. Sort HAR findings by size: the 3-5 largest images usually hold most of the savings. GIF animations first (often 1 MB+), then oversized photos.
- Pick formats (decision table in references/formats.md): photos AVIF with WebP fallback, UI graphics SVG, screenshots WebP lossless or PNG, animations MP4/WebM video. If an image CDN or framework image component exists, use its automatic format and resizing instead of hand conversion.
- Generate sizes and formats with the commands in references/formats.md into a new folder. Show the user a before/after byte table; check visual quality on 2-3 images before batch converting.
- Update markup:
srcset+sizesthat match the CSS layout,width/height,loading="lazy"+decoding="async"below the fold, eager plusfetchpriority="high"for the LCP image only. Ask before editing templates or CMS settings. - Verify: re-run the script with a new HAR; total image KB and the largest image should drop. Check the page visually on mobile and desktop.
Output
Images: 6 requests, 2.3 MB (2.2 MB JPEG/PNG/GIF)
1. sale-banner.gif 1.3 MB -> MP4 loop (~150 KB) in <video autoplay muted loop playsinline>
2. hero-summer.jpg 598 KB, displayed 390-1200 px -> AVIF 480/960/1440 w (~90 KB at 960)
3. shoe-1.jpg 233 KB, displayed 300 px -> 300/600 w WebP (~25 KB)
Markup: 4 product images need width/height; shoe-2 srcset needs sizes; images 5+ lazy
Estimated saving: ~1.9 MB (-80%). Converted files written to optimized/ (originals untouched).