Comment ça marche
An SVG file is XML, so everything XML allows is legal in it: comments, processing instructions, namespace declarations, metadata elements and arbitrary attributes in foreign namespaces. A renderer ignores nearly all of that. The Inkscape namespace declaration, the sodipodi named-view element, the Adobe generator comment, the layer labels and the RDF metadata block together account for the majority of a typical exported file and affect nothing that is drawn. Removing them is the single largest saving available and it is entirely safe.
Attribute-level cleanup is the second pass. Many attributes are written out at their default value — fill-opacity of 1, stroke-linecap of butt, stroke-width of 1 — and a default value is by definition what the renderer uses when the attribute is absent, so removing it changes nothing. Noise attributes such as xml:space, version and enable-background are either obsolete or never consulted. Unreferenced ids are removed only when nothing in the file points at them, since an id is a target for url(#) references in fills, clips, masks and filters, and deleting a referenced one breaks the graphic.
Coordinate precision is where a file can lose a surprising amount of weight with no visual consequence. A path produced by a vector editor routinely carries six decimal places, so a coordinate reads 48.1234567 when 48.12 would render identically at any size a screen can display. Rounding to two decimals typically halves the length of a path's data attribute. Specifying a precision below two is possible and occasionally useful for a large illustration, but the artefacts become visible on curves at one decimal place or fewer.
Gzip is why the raw percentage understates the real gain. Because SVG is text, HTTP servers compress it, and the redundancy in the verbose form means the compressed size is often closer to the optimised size than the raw figures suggest — a file that shrinks by 70 percent raw may shrink by only 40 percent on the wire. Both numbers are reported so the actual benefit is visible rather than assumed. The one case where raw size is what matters is the asset inlined directly into an HTML document, where no separate compression applies, and there the raw saving is the whole saving.
Cas d'usage courants
- Strip editor metadata from icons exported from Figma or Illustrator before committing them.
- Reduce the weight of an inline SVG logo that sits in the critical path of a page load.
- Clean up an SVG before embedding it in an email template or a PDF pipeline.
- Check how much of a file's size is real artwork and how much is tooling overhead.
- Round path coordinates on a map or chart SVG generated programmatically at excessive precision.
- Produce a compact SVG to paste directly into an HTML or JSX file.
Dernière mise à jour: 2026-10-14 — le corps de l'article est affiché en anglais ; l'interface est traduite.