Auto-optimized sprites using `<symbol>` and `<use>`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 96
- Avg merge
- 8h 12m
- Merged PRs (30d)
- 2
Description
Astro Icon is a similar module for Astro projects that also utilizes Iconify under the hood. It automatically optimizes repeated references to the same icon on a page, using a simple approach that results in smaller HTML documents (official documentation).
In a nutshell, the first time the <Icon> component is included on a page, it defines a sprite <symbol> with a unique ID and immediately renders that symbol with the <use> element. If the same icon is referenced again, <Icon> will render only a <use> element, reducing the overall size of the HTML document by referencing the existing <symbol>.
With that said:
<Icon name="logo" />
<!-- First usage generates the following HTML -->
<svg data-icon="logo">
<symbol id="ai:uniqueid"><!-- contents of logo.svg --></symbol>
<use xlink:href="#ai:uniqueid"></use>
</svg>
<Icon name="logo" />
<!-- Additional usage generates the following HTML -->
<svg data-icon="logo">
<use xlink:href="#ai:uniqueid"></use>
</svg>
It'd be nice to have this feature in Nuxt Icon module as well.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Nuxt Icon module's component and its Iconify integration; the issue names no specific files or tests. Review how repeated icon references are rendered, then verify that the first use defines and renders a unique while later uses render only references, with output matching the requested HTML structure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nuxt, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100