Minifying SVG's myself
I remove unused 'id' attributes from SVG's I get from 'openclipart.org'.
I say: '%s:id="[^"]*"::gc' in 'vim'.
I leave in the id's for gradients and filters used within the SVG. I add a unique prefix to these id's so they do not clash with other inline SVG's.
I also remove 'label' attributes.
I also remove 'inkscape' and 'sodipodi' attributes, and 'metadata' which is usually about the 'author' and license.
I remove nearly all namespaces from the 'svg' tag. It seems these are not needed for my inline SVG's. But sometimes the 'xmlns' and 'xlink' namescapes are needed by the 'svgomg' online minifier if an 'xlink:href' is used later in the SVG, maybe to reference a color gradient. I also remove the version as apparently browsers do not use it. My 'svg' tag now usually only has the 'id' and 'viewBox'.
I tried removing the outer 'svg' tags and putting all the SVG's in a 'defs' tag in one global 'svg' tag. But this makes testing the image outside of the HTML more difficult.
I put the SVG through the 'svgomg' online minifier. I turn off the 'Clean up IDs' option' and the 'Remove viewBox' option. This minifier will also remove some of the things I remove manually.

Comments
Post a Comment