-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reuse icons via <svg use>
#44
Comments
For now #41 (comment) works around this using CSS background images with data URLs to avoid HTTP requests. Not great for maintenance, but performant at least. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The way we embed SVGs on the sites is not ideal. They are usually inlined, causing duplicate code to be shipped across the network. For example:
https://developer.chrome.com/en/docs/devtools/javascript/reference/ - which uses the Gotcha aside seven times, we inline the same 372 byte SVG seven times, which sums up to 2,54KB of which 2,17KB could be saved.
Not much, but there are other shortcodes which use more heavy icons, like the
BrowserCompat
shortcode made available for both sites with #41. This is used 17x on https://web.dev/learn/css/pseudo-classes/#hover, adding 18,4KB of SVG code to the site for each instance, totalling in 312,8KB.Other pages on web.dev that use BrowserCompat more than 2x:
By introducing a helper that keeps track of the used icons per page, we could avoid shipping duplicate bytes and also improve DOM size. This would work by giving each SVG an ID and then reuse it like this:
The text was updated successfully, but these errors were encountered: