Live data from Hacker News

Minify Your SVGs

victorzhou.com

21–30 of 66 posts

Re: Minify Your SVGs

#22

We provide hosted service for optimising SVG. If anyone is interested for image optimisation as a service, take a look here: https://www.gumlet.com

There is a typo on this page:

https://www.gumlet.com/how-it-works

I think you mean "images" not "imags"

edit:

Also the link to the docs doesn't work.

Re: Minify Your SVGs

#23
post #15
post #2

Related: https://jakearchibald.github.io/svgomg/

I use it every time I'm using SVG for the web. My only problem is that when pasting SVG directly from Illustrator it finds an invalid character at the end and refuses to use it. I have to paste the SVG into an editor, remove some invisible character at the end, and then paste to svgomg. I reported this and offered to PR but never got an answer: https://github.com/jakearchibald/svgomg/issues/145

My protocol for dealing with no-PR's has been (especially in this case where you can just host the tool on github.io)

1. Just fork it and use your own version until the PR is accepted

2. Directly email the maintainer if you think your PR is worthwhile

3. If you have a bunch of PR's that are pretty useful to others, consider making it a real distributable (and not just a personal) fork if the maintainer still doesn't respond

Re: Minify Your SVGs

#25
I've also noticed the cruft in Inkscape SVG's.

The TXR logo SVG is cleaned with a TXR script:

http://www.kylheku.com/cgit/txr/tree/win/cleansvg.txr

The original looks like this:

http://www.kylheku.com/cgit/txr/tree/win/txr.svg

The cleaned one is not in the repo. It's obtained by "txr cleansvg.txr txr.svg":

  
  
  
  
  
    
      
        
      
    
  

Re: Minify Your SVGs

#26
post #10

Don’t forget to also use GZip or another transport compression on them as well. Text tends to compress well, and can net additional benefits on top of minification.

I ran the examples in the article through gzip. The long one is 789 bytes compressed, and the short one is 266 bytes compressed.

The reality is that while text compresses well, gzip doesn't know what data is relevant. It keeps it all. So for this example, the original long svg contains things like inkscape configuration (the window height, the current layer name, etc.) while the shorter one omits all that. So not emitting that information will always be more efficient than emitting that information and compressing it.

Re: Minify Your SVGs

#27
For inlining, you can even go further and remove that xmlns attribute to end with something around 50 bytes. I'd recommend keeping the viewbox though, since it's required for proper resizing.

Re: Minify Your SVGs

#28
post #10

Don’t forget to also use GZip or another transport compression on them as well. Text tends to compress well, and can net additional benefits on top of minification.

I ran the examples in the article through gzip. The long one is 789 bytes compressed, and the short one is 266 bytes compressed. The reality is that while text compresses well, gzip doesn't know what data is relevant. It keeps it all. So for this example, the original long svg contains things like inkscape configuration (the window height, the current layer name, etc.) while the shorter one omits all that. So not emi…

He means in addition to minifying the SVG, you should compress it for transport (which is likely happening already depending on how you serve it)

Re: Minify Your SVGs

#29
post #10

Don’t forget to also use GZip or another transport compression on them as well. Text tends to compress well, and can net additional benefits on top of minification.

I ran the examples in the article through gzip. The long one is 789 bytes compressed, and the short one is 266 bytes compressed. The reality is that while text compresses well, gzip doesn't know what data is relevant. It keeps it all. So for this example, the original long svg contains things like inkscape configuration (the window height, the current layer name, etc.) while the shorter one omits all that. So not emi…

Of course, but even the minified versions should net some benefits with compression. Most SVGs probably fit in 7-bit ASCII, which on itself should lead to improvements via (Huffman?) compression. Importantly, as was pointed out, I say “also” not “instead.”
Post reply on HN