broken-images
它能做什么
这项技能检查项目中的图片引用,找出缺失的文件和会失败的路径。适合希望图片可靠加载的网页开发者和网站所有者。
适用场景
- ✓当访客在页面上看到破损的图片图标时。
- ✓当图片路径指向项目中不存在的文件时。
- ✓当图片来自用户数据或可能消失的外部链接时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/broken-images/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请扫描我的项目,找出指向缺失文件的图片路径,并在需要的地方添加备用图片。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查图片的 src 属性和背景图片是否指向缺失的文件,修正错误的路径,并在需要时添加错误处理程序,在原图加载失败时换成备用图片。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Fix broken images
A broken image shows an ugly placeholder icon, breaks visual layouts, and communicates that the site is poorly maintained. If the broken image is the Largest Contentful Paint element, it also harms LCP scores. On e-commerce sites, a missing product image can directly reduce purchase intent.
Quick Reference
- Broken images show an icon and console error—validate all
<img src>paths at build time - Use
onerrorhandlers to swap broken<img>elements to fallback images - Set
this.onerror=nullinside the handler to prevent infinite error loops - Test with DevTools Network tab blocked requests to verify fallback behaviour
Check
Scan all <img> src attributes and CSS background-image URLs in this codebase. Identify: 1) Any relative or absolute paths that point to files not present in the project. 2) Any <img> elements without an onerror handler or fallback mechanism. 3) Hardcoded external image URLs that may become unavailable. 4) Dynamic image paths constructed from user data without existence checks. Report each broken or potentially broken image with its file path and line number.
Fix
For each broken image: 1) Correct the file path if the image exists but the path is wrong. 2) Add the missing image asset if it was omitted. 3) For images that may fail at runtime, add an onerror handler: onerror="this.src='/images/fallback.png'; this.onerror=null;". 4) For React/Vue components, implement an onError callback that swaps the src to a placeholder. 5) For external images, consider downloading and self-hosting or using a CDN with fallback. Always set this.onerror=null to prevent infinite error loops.
Explain
Explain why broken images degrade user experience and how browsers handle them. A 404 response for an image shows the browser's broken-image icon, causes a console error, and—if the image is the LCP element—delays Core Web Vitals metrics. Search engines cannot index missing images, affecting image SEO. Monitoring image errors proactively prevents broken experiences from reaching users.
Code Review
Review image assets, markup, and delivery configuration related to Fix broken images. 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/broken-images
常见问题
图片损坏除了影响外观,还有什么问题?
这项技能说明,如果损坏的是页面的主图,可能会损害加载性能评分。
错误处理程序做什么?
如果原图加载失败,它会换成备用图片,并且经过设置,不会陷入循环。
怎样测试备用图片?
这项技能建议在浏览器开发者工具中阻止请求,以查看备用图片是否生效。
详情
作者的原始描述
Use when reviewing image assets, markup, and CDN or build transforms related to Fix broken images. Check encoded size, rendered size, loading strategy, and above-the-fold impact together.
热度
- GitHub 星标
- 75k
- 排名
- #2760
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。