What does HackerNews think of svgo?

⚙️ Node.js tool for optimizing SVG files

Language: JavaScript

#10 in JavaScript
#5 in Node.js
Look at software you use and identify underlying libraries.

SVGO https://github.com/svg/svgo is used by many graphics software but hasn't seen donations commensurate with usage https://opencollective.com/svgo

You're being modest. This is easily the most performant option... although it means losing interactivity (right clicking equations on GitHub allows copy to clipboard, A11y features, etc).

Running the JS client side, like GitHub, means blocking the thread. You're either going to be 1. delaying other JS from running, or 2. rendering late, shifting the layout – which is what GitHub has chosen: https://imgur.com/a/y47haf9

(Sending the rendered div's is a non-starter. Large document sizes delay domContentLoaded, slow down browsers, aren't shared cacheable resources, etc.)

Your approach, then. On your page there are 178 SVGs. Total gzipped size is 490KB. SVGO[0] gets that down to 311KB – that's 1.74KB transferred per equation. These are non-blocking, immutable, cacheable assets. Brilliant.

Upgrades:

- Figure out viewbox and inline height/width values on the HTML so no layout jank (aka "Cumulative Layout Shift"/CLS) occurs. Unsure if this is possible for inline math.

- Add `loading="lazy"` afterwards. Users that don't scroll the entire length of the page won't suffer unneeded downloads, and the inlined sizes will prevent late CLS for those that do.

- Maybe re-add interactivity? Cheap option: just support copying alt-text in a context menu.

[0] https://github.com/svg/svgo

Often, you can considerably reduce the file size of an SVG text file without a noticeable reduction in perceptual quality just by reducing the precision of the coordinates.

The awesome SVG Optimizer [1] has a filter (cleanupNumericValues) to process SVG files to a fixed precision.

The equally awesome SVG Optimizer Missing Gui (SVGOMG) [2] provides a web-based GUI [3] to interactively adjust precision and see the resulting render (and file-size).

[1] https://github.com/svg/svgo

[2] https://github.com/jakearchibald/svgomg

[3] https://jakearchibald.github.io/svgomg

If you wanna convert images for web, I use tools like:

  svgo (SVG Optimization)
  colorist / avifenc (AVIF)
  cwebp (webp)
  convert (ImageMagick, everything else)
because ImageMagick is able to convert MOST of thse, but not every format.

https://github.com/svg/svgo

https://github.com/joedrago/colorist

https://developers.google.com/speed/webp/docs/cwebp

https://imagemagick.org/

(Not a direct reply to you)

If anyone likes the icons, doesn't like the float precision, and is in a Node environment, https://github.com/svg/svgo has a bunch of config options to help optimize SVGs. https://lean-svg.netlify.app/ is a site that lets you play with settings to see what kind of gains you can get.

Unfortunately the reference to the actual minifier, SVGO (https://github.com/svg/svgo), is buried in the middle of the post.

SVGO is an incredible project driven by a single volunteer in spare time (originally Kir Belevich https://twitter.com/deepsweet , and for the last few years Lev Solntsev https://twitter.com/ruGreLI). It's the type of project you probably use regularly behind another tool like Sketch or SVGOMG (https://jakearchibald.github.io/svgomg/). They accept donations (https://www.paypal.me/deepsweet) and you should definitely consider contributing if you find it useful.

ImageTracer is a simple raster image tracer and vectorizer that outputs SVG, 100% free, Public Domain.

Available in JavaScript (works both in the browser and with Node.js), "desktop" Java and "Android" Java:

https://github.com/jankovicsandras/imagetracerjs

https://github.com/jankovicsandras/imagetracerjava

https://github.com/jankovicsandras/imagetracerandroid

You can use svgo to optimize the SVG afterwards: https://github.com/svg/svgo

Most vector tools export to SVG, and you can use SVGO[1] to clean it up and optimize it.

1: https://github.com/svg/svgo

SVGs generated from popular vector editing softwares can get very complex with cascading style overrides, transformations etc. Even though SVGz would reduce the file size, parsing the SVG tree and rendering will still be unoptimized.

Optimization tools do exist [1] to simplify the tree but they can do only so much good[0]. I think this format, built with optimality might be a solution.

[0]: Anecdotal. I once had to edit ~20 icons. The client had provided SVGs because they'd somehow lost the original AI files. When I imported them in Sketch 3, the nesting, masks, and transforms applied were absolutely horrifying! I had to optimize the icons using [1], which did remove the masks and transforms, but in the end I had to manually edit SVG's XML source to fix nestings. sigh.

[1]: https://github.com/svg/svgo

I've cleaned thousands of SVGs with: https://github.com/svg/svgo

  npm install -g svgo
  svgo -f /path/to/svg/files
If all you want to do is clean your svg files, svgo is the tool to use: https://github.com/svg/svgo
Svgs usually contain a lot of redundant and useless information. We clean the svgs using SVGO, https://github.com/svg/svgo (and a few of our own plugins) to get more beautiful svg files. The output often gets bloated by apps like Sketch, this way we end up with a better output.
Yes, SVGO is really good at this and other kinds of SVG optimisation and manipulation: https://github.com/svg/svgo/
With font awesome, you are automatically using all of the icons however most sites likely use about 1%-5% of the total available icons. That means using font awesome is an unnecessary bloat on most sites. It would be nice if you could download each icon as a separate SVG (maybe you can, I didn't see how).

I prefer to find the SVG elements I need and base64 encode them directly into my CSS. That way you only include the assets you are using, minimize total KB and network requests. There are two tools I use to help with this:

1. https://github.com/svg/svgo (node)

2. https://gist.github.com/mrinterweb/11303706 (ruby - I wrote this one)

There's a great little node.js-based tool called SVGO for removing the fluff and optimising SVG files: https://github.com/svg/svgo