Optimize SVG size in Data URLs

Original link: https://hsiaofeng.com/archives/201.html

Data URLs , ie URLs prefixed with the data: protocol, allow content creators to embed small files into documents.

 data:[<mediatype>][;base64],<data>

The following steps will keep the Data URLs of the SVG file as short as possible.

Use Scour to optimize SVG source code. Here I use Inkscape to save as优化的SVG .

Generate Data URLs using the mini-svg-data-uri tool. Here I use RunKit for online generation.

 var miniSvgDataUri = require("mini-svg-data-uri") var svg = ` [ SVG 源码] ` var optimizedSVGDataURI = miniSvgDataUri(svg);

Compressing an SVG yields a final length of 1421 characters using this method. The same SVG, without Scour optimization but generated by mini-svg-data-uri, has a length of 2924 characters. The same SVG, directly converted to Base64, has a length of 3855 characters.

This article is reproduced from: https://hsiaofeng.com/archives/201.html
This site is for inclusion only, and the copyright belongs to the original author.