Sam Breed

Product Developer, Investor

← wiki

SVG icon sprites

What I've learned about optimizing SVGs to load icons

First posted on

SVGs are pretty cool.

Most applications use a variety of icons. High-quality open source icon sets are widely available. React (and adjacent frameworks) treat SVGs as interchangable with components. The developer ergonomics of these large packages is hard to beat.

But inlining SVGs in JavaScript is probably the least cool way to deliver static images to your users.

Inline SVGs are not ideal for a few reasons:

You could get around this with precise bundle splitting and file hashing across releases, but I consider that high-effort. Most frameworks optimize for bundling around routes rather than modules. [citation needed]

Sprite sheets are cool

SVG icons

Example

Here’s an over-wrought example of paging through lots and lots of icons.

Categories