Active
Project:
Drupal core
Version:
main
Component:
theme system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
4 Aug 2014 at 08:45 UTC
Updated:
6 Jun 2026 at 12:26 UTC
Jump to comment: Most recent
Follow-up to #2032773: Use Libricons (icon font) in Seven, consider using it more broadly in core
SVG assets provided by Drupal core vary widely in code consistency and size. We don't have a standardized set of guidelines to follow for creating new optimized SVGs in core and contrib.
Optimize performance of core SVG based on a defined set of guidelines that both core and contrib can follow:
fill- over stroke-style paths.<path>s of the same fill/stroke (when practical).<g> (groups) down to a single path (when practical).svgo to strip harmful tags (like id), strip unnecessary attributes, order attributes, combine groups and paths, and round paths to 1, 2, or 3 decimal places (see floatPrecision below).xmlns, aria-hidden="true" focusable="false", viewBox="0 0 X Y" width="X" height="Y", fill and stroke (optional)floatPrecision: 1 is reasonable as long as the optimized output is visually checked. For very simple grid-aligned icons should aim for integer precision when possible and doesn't compromise the design aesthetic; for curves or hand-tuned paths, 2 decimals may be safer.svgo to core yarn dependencies; use it to run the optimization script.
Comments
Comment #1
damien tournoud commentedVirtually 100% of the browsers will accept SVGs served with a
Content-Encoding: gzip, because that's just a standard HTTP mechanism. On the other hand, virtually no browser supports SVGz served without the special header, or reading SVGz images fromdata:uris.Comment #2
jwilson3The special header part I knew about. Good info here by the way: http://kaioa.com/node/45. The general consensus is that not compressing your own static resources and letting mod_deflate do it for you is considered wasteful.
The second part about "Reading SVGz images from data uris" I had suspected may be true, but wasn't able to turn up any documentation about it. Here is something I just found that corroborates your statement: http://benfrain.com/tips-for-using-svgs-in-web-projects/
So It looks like we would have to choose between compressing to SVGZ at their separate URLs (to reduce kilobytes), OR embedding regular SVGs as data uris inside CSS (to reduce http requests). I would lean towards the later. What do you think @Damien T?
Comment #3
jwilson3Just noticed dreditor cloned this with the wrong status. No patch here yet. Resetting to Active.
Comment #4
jwilson3We can also optimize svgs by doing manual review of each icon in an image editor tool like inkscape or illustrator to remove extraneous path points.
Comment #5
jwilson3Incorporated feedback from #1 into issue summary.
Comment #6
jwilson3Comment #7
jwilson3Pulling over tags from #1849078: Replace many toolbar icon files with a single CSS sprite image for visibility.
Comment #8
lewisnymanRelated: #2306499: Experiment with styling inline SVGs using CSS
Comment #9
damien tournoud commented@jwilson3: typically, we serve CSS themselves compressed, so in terms of pure size it should not make that big of a difference (needs some experimentation, of course) between separate SVGz and SVG embedded as base64 inside CSS.
Thinking about it, we might want to synchronize the base64 encoding so that SVG tags always end up at byte boundaries to improve the compression process (because base64 encodes 3 original bytes into 4 encoded bytes, you are going to get a vastly different representation for the same tag if it is not aligned on a 3-byte boundary, so we might want to add space padding so that all the tags end up on a boundary to improve compression rates).
Comment #10
jbrown commentedHere is the issue for serving SVGZ with the correct encoding: #2092245: SVGZ isn't served with correct encoding.
Comment #11
jbrown commentedComment #12
joelpittetI've gulpified and automated the SVG generation of libricons, I could also add some kind of optimize there too if you'd like. Got commit access from @ry5n.
Comment #13
andrewmacpherson commentedBump version
Comment #29
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #30
smustgrave commentedwanted to bump this 1 more time.
Comment #32
jwilson3The issue summary and title have been updated. Several items were removed from scope, including SVGZ support, an icon stylesheet, and base64-encoded SVGs.
These days, HTTP requests are generally cheaper than the complexity of creating and maintaining SVG sprites. Supporting multiple icon colors is also better handled with inline SVGs. That is out of scope for this optimization-focused issue, but we can at least prepare core SVGs so they can be inlined safely and accessibly later.
The updated scope is therefore narrower: provide a standardized SVG optimization pipeline in core, using a Yarn dependency on SVGO, with documented commands and options for optimizing SVGs consistently.
Speculative future follow-up: add a GitLab CI check that validates whether newly introduced SVGs are optimized.
Comment #33
jwilson3