Image optimization

From hashgraph-online/awesome-codex-plugins · View interactive version

Image optimization is an AI agent skill from the GitHub repository hashgraph-online/awesome-codex-plugins. Expert guidance on image optimization for web performance. Use when auditing or improving image delivery, Core Web Vitals (LCP/CLS/INP), responsive images (srcset/sizes), lazy loading, preloading, image CDN pipelines (Sirv, Cloudinary, imgix, Vercel, Cloudflare), format choice (AVIF, WebP, JPEG XL,

How to use this skill

Skill file

Image Optimization Expert

Default Workflow

  1. Inspect the real surface before prescribing changes: rendered HTML, framework image components, network waterfall, build output, CDN URLs, and asset inventory.
  2. Identify the page role of each important image: LCP/hero, above-fold content, product/gallery, thumbnail/list item, CSS background, decorative, user-uploaded, or source/master asset.
  3. Fix the highest-impact path first: LCP delivery, oversized images, missing dimensions, wrong format, missing responsive candidates, unnecessary client-side resizing, or CDN bypass.
  4. Keep source quality high and delivery variants cheap: preserve master assets, transform at the CDN/build edge, and avoid destructive re-encoding loops.
  5. Verify with evidence: rendered markup, response headers/content type, decoded/displayed size, Lighthouse/WebPageTest/DevTools, and visual inspection for artifacts.

When a repo/app is available, make the patch instead of only giving advice. Prefer local framework conventions over generic snippets.

Fast Audit Checklist

Use The Audit Script

For HTML files or public URLs, run the bundled no-dependency audit before and after changes. The script lives in this skill's own scripts/ directory — resolve it from the skill's base directory (shown when this skill loads), not the target project:

node <skill-base-dir>/scripts/audit-images.mjs ./dist/index.html
node <skill-base-dir>/scripts/audit-images.mjs --head https://example.com/
node <skill-base-dir>/scripts/audit-images.mjs --json https://example.com/ > image-audit.json

The script checks image markup, srcset/sizes, preload hints, likely LCP mistakes, oversized CDN widths, CSS background images, known image CDNs (Sirv, Cloudinary, imgix, Cloudflare, Next.js, and others), and optional HTTP headers/content length. It reads the server HTML only; images that client-side JS injects do not appear, so compare with DevTools for SPAs.

Decision Matrix

| Situation | Preferred Action |

| --- | --- |

| Static/project-owned images | Generate responsive variants at build time or move masters to an image CDN. |

| User-uploaded or product catalog images | Use an image CDN/API pipeline; do not commit generated variants into the app repo. |

| Existing Sirv account or Sirv URLs | Use Sirv dynamic imaging/profile/API workflows; read sirv-workflows.md. |

| Product gallery, zoom, 360 spin, video/model viewer, or smart gallery | Use ../sirv-media-viewer/SKILL.md before hand-building gallery behavior. |

| Next.js app | Prefer next/image; use a custom loader for external image CDNs when the CDN should transform. In Next.js 16+, priority is deprecated: use fetchPriority="high" (or preload for exactly one LCP image), and add every quality value to images.qualities. |

| CSS background hero | Consider replacing with semantic <img>/picture; if it must remain CSS, use image-set() with type() and preload carefully. |

| Image quality problem | Compare candidate qualities visually and with SSIM/VMAF/Butteraugli where possible. |

| Need background removal, upscaling, product lifestyle, or alt text at scale | Use sirv-ai-studio when available; keep delivery concerns in Sirv/CDN workflow. |

When To Read References

Also load sibling skills when the task crosses into their specialty:

Default Recommendations

| Use Case | Format/Delivery Default |

| --- | --- |

| Photos and product images | AVIF/WebP via auto negotiation; JPEG fallback when needed. |

| Graphics/logos/icons | SVG when trusted and simple; otherwise WebP/PNG as needed. |

| Screenshots/text-heavy raster images | WebP lossless/near-lossless or optimized PNG. |

| Short animations | Animated WebP or video; avoid large GIFs. |

| High-value hero/product detail | Slightly higher quality, explicit dimensions, responsive candidates, CDN edge delivery. |

| Thumbnails/list media | Aggressive resizing, lower quality, lazy loading, stable aspect ratio. |

Quality starting points:

| Format | Starting Quality |

| --- | --- |

| JPEG | 75-85, higher for product/detail |

| WebP | 75-85 lossy; lossless for sharp graphics |

| AVIF | 60-75 for most photos |

| PNG | Lossless, then optimize or convert when safe |

Common Mistakes To Catch

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.