image-optimization
它能做什么
这项技能审查项目中的所有图片,并检查每张图片是否存在常见的网页性能问题。适用于希望页面快速、稳定的开发者和设计师。
适用场景
- ✓当你的页面加载缓慢,且图片可能是主要原因的时候。
- ✓当图片缺少尺寸属性或懒加载设置的时候。
- ✓当你希望在上线前全面审查图片处理方式的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/image-optimization/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请审查我网站上的所有图片,并修复性能问题。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查每张图片的格式、响应式尺寸、宽度和高度、懒加载以及文件大小。它会按严重程度对问题分组,并建议修复方法,例如使用带 WebP 或 AVIF 的 picture 元素和 srcset 尺寸。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Optimize all images for web
Images typically account for 50%+ of page weight. Unoptimized images cause slow load times, wasted bandwidth, poor Core Web Vitals scores, and frustrated users—especially on mobile networks.
Quick Reference
- Use modern formats: AVIF > WebP > JPEG/PNG
- Compress images to 80% quality for photos
- Always provide responsive srcset for different screen sizes
- Use
<picture>element for format fallbacks
Check
Scan this codebase for all image assets and <img> elements. For each image, verify: 1) Format is appropriate (WebP/AVIF for photos, SVG for icons, PNG only for transparency). 2) Responsive srcset and sizes attributes exist for images > 100px wide. 3) width/height attributes are present to prevent layout shift. 4) loading='lazy' is set for below-fold images. 5) File sizes are reasonable (< 200KB for photos, < 50KB for graphics). Report issues grouped by severity with file paths.
Fix
For each image optimization issue found: 1) Convert JPEG/PNG photos to WebP with AVIF fallback using <picture> element. 2) Add srcset with 400w, 800w, 1200w, 1600w variants and appropriate sizes attribute. 3) Add explicit width/height attributes matching aspect ratio. 4) Add loading='lazy' to images below the fold, keep priority images without lazy loading. 5) Compress images to 80% quality for photos, 60% for AVIF. 6) Use SVG for icons and logos. Show the corrected HTML with optimized image markup.
Explain
Explain the impact of image optimization on Core Web Vitals, specifically how unoptimized images affect Largest Contentful Paint (LCP) and Cumulative Layout Shift (CLS). Cover the compression differences between AVIF, WebP, and JPEG formats, when to use each, and browser support considerations. Describe how srcset and sizes work together to serve appropriately-sized images, and why width/height attributes prevent layout shift. Include bandwidth savings calculations and loading performance improvements.
Code Review
Review image assets, markup, and delivery configuration related to Optimize all images for web. Flag exact files or components where format choice, sizing, or loading behavior violates the rule, and describe how to confirm the fix in DevTools.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/images/image-optimization
常见问题
每张图片都应该懒加载吗?
不应该。这项技能指出,应保留优先图片(例如页面顶部的主图)不做懒加载。
它推荐什么格式?
它首先推荐 AVIF,其次是 WebP,并以 JPEG 或 PNG 作为备用,图标和标志则使用 SVG。
为什么要添加宽度和高度?
这项技能指出,明确的尺寸可以防止页面加载时发生布局偏移。
详情
作者的原始描述
Use when reviewing image assets, markup, and CDN or build transforms related to Optimize all images for web. Check encoded size, rendered size, loading strategy, and above-the-fold impact together.
热度
- GitHub 星标
- 75k
- 排名
- #2885
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。