Trevin serves as the VP of Marketing at WebFX. He has worked on over 450 marketing campaigns and has been building websites for over 25 years. His work has been featured by Search Engine Land, USA Today, Fast Company and Inc.
One way to shave off a few extra bytes from a web page is to optimize SVG files. I’ll show you a quick method for doing this. OK, so generally, you’ll create an SVG file through your favorite vector graphics editor.
My choice is Adobe Illustrator, but this will work in other programs. Here you can see the vector graphic I created with Illustrator, a magnifying glass icon: Once the vector graphic is finished, you’ll typically export it to an SVG file for web use. I just followed the official guide for exporting SVG for the web with Adobe Illustrator to create the SVG file for the magnifying glass icon: An SVG file is simply composed of XML markup that tells web browsers how to render the image.
For us, this just means we can open and view the source code of SVG files in a text editor. Here’s the markup Adobe Illustrator automatically generated for me:
As you may have seen above, the code for my magnifying glass icon has extra stuff that aren’t really needed. The hard way of optimizing your SVG files is manually cleaning up your code.
And if you need help with this, check out the SVG optimization guide by Dudley Storey that shows you the things to look out for. The manual cleanup method is a good thing to do a few times, just so you know how it all works and know what’s going on when a tool optimizes an SVG file for you. But code cleanup can almost always be automated.
And imagine if you had a ton of SVG files, manually cleaning up their source code isn’t efficient or practical. This is where Kraken.io steps into the picture. Kraken.io optimizes web images such as JPG, PNG and SVG files.
Simply drag-and-drop SVG files into the tool, and it will do all the work for us. Here’s the optimized SVG code after being run through Kraken.io:
You’ll notice it removed unneeded code such as comments, code formatting, and spaces from my SVG file. Using this trick, the SVG file size was reduced by about 37% without sacrificing any image quality whatsoever (i.e.
this was a lossless compression). You can download the source files of the icon used in this tutorial for hands-on exploration.