Community图像github.com

image-optimization-audit

Audit page images for weight, format, sizing and loading behaviour, then produce a conversion and markup plan. Reads saved HTML (missing width/height, srcset without sizes, large images without srcset, lazy-loading on the first images or missing further down, JPEG/PNG outside a picture element with AVIF/WebP, animated GIFs) and HAR files (images over a KB budget, legacy formats with real byte counts, uncompressed SVG, broken image requests, total image weight). Includes exact commands for cwebp, avifenc, ImageMagick and sharp, and responsive image markup. Use when images are the heaviest part of a page, Lighthouse flags "Properly size images", "Serve images in next-gen formats", "Efficiently encode images", "Defer offscreen images" or "Improve image delivery", or the user asks to convert images to WebP/AVIF or set up srcset.

image-optimization-audit 是什么?

image-optimization-audit is a Claude Code agent skill that audit page images for weight, format, sizing and loading behaviour, then produce a conversion and markup plan. Reads saved HTML (missing width/height, srcset without sizes, large images without srcset, lazy-loading on the first images or missing further down, JPEG/PNG outside a picture element with AVIF/WebP, animated GIFs) and HAR files (images over a KB budget, legacy formats with real byte counts, uncompressed SVG, broken image requests, total image weight). Includes exact commands for cwebp, avifenc, ImageMagick and sharp, and responsive image markup. Use when images are the heaviest part of a page, Lighthouse flags "Properly size images", "Serve images in next-gen formats", "Efficiently encode images", "Defer offscreen images" or "Improve image delivery", or the user asks to convert images to WebP/AVIF or set up srcset.

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/saizul/web-performance-skills/tree/HEAD/skills/image-optimization-audit

Installed? Explore more 图像 skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

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

  1. 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
    
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Update markup: srcset + sizes that match the CSS layout, width/height, loading="lazy" + decoding="async" below the fold, eager plus fetchpriority="high" for the LCP image only. Ask before editing templates or CMS settings.
  7. 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).

Individual skills in this repo

This repo contains 2 individual skills — each has its own dedicated page.

render-blocking-resources

Find and remove what blocks first paint. Lists the critical path of a saved HTML page in document order and flags parser-blocking scripts in the head and early body, third-party stylesheets and scripts on the critical path, CSS @import chains, document.write, A/B-testing anti-flicker snippets, oversized inline CSS, too many blocking stylesheets, missing and excessive preconnect hints. Explains defer vs async vs type=module, critical CSS inlining, non-blocking CSS loading and resource hints with copy-paste snippets. Use when Lighthouse reports "Eliminate render-blocking resources", "Render blocking requests" or a long critical request chain, FCP or LCP render delay is high, the page stays white for seconds, or the user asks whether to use defer or async.

web-font-loading

Make web fonts fast and stable. Audits HTML and CSS for @font-face rules without font-display or with block, fonts without a WOFF2 source, Google Fonts links without display=swap or preconnect, too many weights, font preloads missing crossorigin (double downloads) or pointing at unused files, CSS @import of font stylesheets, icon fonts, too many font files and swapping fonts without metric-matched fallbacks. Covers self-hosting Google Fonts, subsetting with unicode-range and pyftsubset, variable fonts and size-adjust fallback faces that remove font-swap layout shift. Use when Lighthouse flags "Ensure text remains visible during webfont load" or "Font display", text is invisible or flashes while loading, fonts cause layout shift, or the user wants to self-host Google Fonts.

相关技能