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

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

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

可以这样问 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.

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能