跳到正文
Skillpedia
网站与界面(前端)75k · #2760

broken-images

它能做什么

这项技能检查项目中的图片引用,找出缺失的文件和会失败的路径。适合希望图片可靠加载的网页开发者和网站所有者。

适用场景

  • ✓当访客在页面上看到破损的图片图标时。
  • ✓当图片路径指向项目中不存在的文件时。
  • ✓当图片来自用户数据或可能消失的外部链接时。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/broken-images/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/broken-images/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 onerror handlers to swap broken <img> elements to fallback images
  • Set this.onerror=null inside 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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2760
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能