svg-inline
它能做什么
这项技能检查直接写在 HTML 或组件中的 SVG 图形。适用于希望页面加载更快、又不损失设计效果的开发者。
适用场景
- ✓当页面包含体积很大的内联 SVG 图形,使 HTML 变得很臃肿的时候。
- ✓当同一个图标被复制到网站的许多地方的时候。
- ✓当你在审查某个 SVG 是否必须内联,还是可以作为单独的图片文件的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/svg-inline/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的首页很慢,HTML 非常大。其中有一个直接粘贴进来的大型 SVG 标志。请帮我检查一下。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会测量每个内联 SVG 的大小,检查它是否重复出现,并判断它是否真的需要内联。然后它会推荐更小或外部的方案。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Manage inline SVG size and complexity
A complex illustration exported from Figma can easily be 50-200KB of SVG markup. Inlined in HTML, it blocks the HTML parser until it is processed, cannot be cached independently, and balloons every page response. Extracting it to an external file allows browser caching and deferred loading. For icon systems, SVG sprites or component libraries avoid duplicating path data across every page.
Quick Reference
- Only inline SVG when you need CSS hover/animation on individual paths—static SVGs belong in
<img>tags - Keep inline SVGs under 1KB (ideally under 500 bytes) after SVGO optimisation
- Reused icons should be SVG sprites or framework components—not copied inline multiple times
- Run all SVGs through SVGO before inlining to strip editor artefacts
Check
Scan HTML files and React/Vue components for inline <svg> elements. For each inline SVG: 1) Measure its character count—flag any over 1KB (approximately 1000 characters). 2) Check if it is reused in multiple places (should be a component or sprite). 3) Check if SVGO has been run (look for redundant attributes, inline styles that could be CSS classes, or editor comments). 4) Check if the SVG needs to be inline for CSS styling/animation, or if <img src="file.svg"> would suffice. Report each large inline SVG with its size and location.
Fix
For each problematic inline SVG: 1) Large, non-interactive SVG (e.g., illustration): extract to .svg file and reference with <img src="illustration.svg" alt="...">. 2) Reused icon: create an SVG sprite or React component. 3) SVG needing CSS interactivity (hover, animation): keep inline but run through SVGO first—remove editor artefacts, merge paths, remove redundant attributes. 4) For React projects, use SVGR to import SVGs as components—they tree-shake unused SVGs. 5) Show before/after size comparison.
Explain
Explain the trade-offs of inline SVG. Inline SVG allows CSS styling (fill, stroke) and JavaScript animation on individual paths, which external SVG files or <img> elements cannot support. However, large inline SVGs bloat the HTML, delay HTML parser completion, cannot be cached separately from the page, and duplicate markup when used in multiple places. The guidance is: use inline SVG only when you need CSS/JS interactivity; use <img src="file.svg"> or CSS background for static SVGs; use SVG sprites or React components for reused icons.
Code Review
Review image assets, markup, and delivery configuration related to Manage inline SVG size and complexity. 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/svg-inline
常见问题
什么时候保留内联 SVG 是合适的?
这项技能指出,当你需要为单个部分添加 CSS 悬停或动画效果时,内联 SVG 很有用。静态图形通常应放在图片标签中。
多大算太大?
这项技能建议优化后的内联 SVG 保持在约 1 KB 以下,最好在 500 字节以内。
这项技能会删除图形吗?
不会。它建议把图形移到外部文件或精灵图(sprites)中,而不是删除它们。
详情
作者的原始描述
Use when reviewing image assets, markup, and CDN or build transforms related to Manage inline SVG size and complexity. Check encoded size, rendered size, loading strategy, and above-the-fold impact together.
热度
- GitHub 星标
- 75k
- 排名
- #3042
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。