SVGs and child nodes referenced from local SVG sprite count towards "Avoid an excessive DOM size"
See original GitHub issueProvide the steps to reproduce
- Run LH on https://andro4all.com/
What is the current behavior?
SVGs pointing to a local svg are adding nodes like they were the whole svg.
<svg class="mrf-Icon mrf-Icon--s">
<use xlink:href="#mrf-Icon--bullet"></use>
</svg>
becomes
<svg class="mrf-Icon mrf-Icon--s">
<use xlink:href="#mrf-Icon--bullet">
<!-- shadow root -->
<svg id="mrf-Icon--bullet" viewBox="0 0 24 24">
<circle cx="12.5" cy="12.5" r="4.5"></circle>
</svg>
</use>
</svg>
So, lighthouse evaluates this nodes too.
What is the expected behavior?
This svgs are pointing to a shared sprite SVG, so, lighthouse doesn’t have to add the nodes inside the use tag. This rule penalizes reusing svgs instead of adding a new svg all the time.
Replacing this SVGs for dummy nodes in this page, for instance, like
<span class="mrf-Icon mrf-Icon--s">
<span xlink:href="#mrf-Icon--bullet"></span>
</span>
decreases the total by 376 nodes.
Environment Information
- Affected Channels: Devtools
- Lighthouse version: Lighthouse 4.0.0-beta
- Node.js version: macOS
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:12
Top Results From Across the Web
Avoid an excessive DOM size (Inline SVG or SVG file tag)?
It becomes an issue when the DOM has over a total of 1500 nodes, a greater Depth of 32 nodes and a parent...
Read more >Too Many SVGs Clogging Up Your Markup? Try `use`.
This works and renders just fine, but results in a bloated DOM tree, where each shape is represented as separate nodes. Displaying all...
Read more >Automatic Translation of Interactive SVGs to a Multithread ...
Abstract—. The dominant markup language for Web visualizations—Scalable Vector Graphics (SVG)—is comparatively easy to learn, and is open,.
Read more >Using SVG and Vue.js: A complete guide - LogRocket Blog
js. From the simple question of how best to load SVG files into your templates, to handling animations and accessibility, there are plenty...
Read more >How your favourite UI libraries manage their icons
The a2k-icon component cloned these SVGs into the DOM via use . ... custom icons, simply pass through your SVG node as a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Lighthouse counts the same number of pixels as the number of times snark has solved a GitHub issue 😉
Unless there’s evidence someone can point to that the original concern is not valid for SVGs with
<use>
, Lighthouse won’t be treating them any differently. I’m skeptical that rendering additional copies of an SVG is a completely free operation.Also keep in mind, this audit has absolutely no impact on the performance score and is just a diagnostic pointing to a potential issue. As with everything in the performance section, if the metrics are good, the score is good, skip the diagnostics. If the metrics are bad, then the diagnostics like this are a good place to start investigating.
Just curious, will you count as dom objects actual pixels…?