Reducing SVG Bloat: Leveraging SVGO Multipass and Precision
Stop leaving bytes on the table. Learn how SVGO's multipass feature and floatPrecision settings can aggressively shrink SVG file sizes without breaking your UI.
06 May 2026, 03:52 UTC

Exporting SVGs from design tools like Figma or Adobe Illustrator often results in files cluttered with editor-specific metadata, hidden layers, and coordinate precision that exceeds what a screen can actually render. While running these files through SVGO (SVG Optimizer) provides an initial win, a single pass often leaves bytes on the table. The problem is that SVG optimization is non-linear: cleaning one element often reveals a new opportunity for another plugin to further simplify the code.
To achieve the smallest possible footprint, you need to implement a multipass strategy. This forces SVGO to loop through its plugin suite repeatedly until the file reaches a stable state where no further changes are detected.
The Logic of the Optimization Loop
SVGO uses a modular plugin architecture where each plugin targets a specific redundancy. For example, removeMetadata strips XML tags, while simplifyPaths reduces the number of commands in a path string. Because these plugins operate independently, the output of one can trigger the conditions required for another.
Without multipass, SVGO executes the plugin list once. If simplifyPaths creates a new numeric redundancy, the cleanupNumeric plugin—which may have already run—won't see it until the next execution. Enabling multipass: true ensures that the tool iterates until a full pass completes with zero modifications, capturing these cascading optimizations.
Balancing Byte Size and Visual Fidelity
The most impactful way to reduce size beyond metadata removal is controlling floatPrecision. This setting determines how many decimal places are kept for coordinates. Reducing precision from five decimals to two can significantly shrink a file, but setting it too low can cause "warping" or gaps between vector shapes.
To manage these settings without breaking your UI, use a svgo.config.js file. This allows you to whitelist IDs that are required for CSS selectors or JavaScript animations, preventing the cleanupIds plugin from renaming them.
Example Configuration
Below is a configuration tailored for aggressive size reduction while protecting specific functional elements:
module.exports = {
multipass: true, // Loop until no further changes are detected
plugins: [
'preset-default',
{
name: 'cleanupIds',
options: {
// Prevent renaming of IDs used in external CSS/JS
preserve: ['main-logo-path', 'animated-circle']
}
},
{
name: 'cleanupNumeric',
options: {
// Trade-off: 2 decimals usually preserves visual integrity
floatPrecision: 2
}
}
]
};
Implementation and Verification
To apply this configuration, run SVGO from your terminal. Ensure you have the SVGO package installed via npm.
# Run SVGO using a specific config file # Required permissions: Read/Write access to the directory npx svgo input.svg -o output.svg --config svgo.config.js
Verification Steps:
- Check Precision: Open
output.svgin a text editor. Search for coordinate values; they should be truncated to two decimal places (e.g.,10.12instead of10.12345). - Verify IDs: Search for
main-logo-path. If it exists in the output, thepreserveoption is working. - Compare Size: Run the command once with
multipass: falseand once withmultipass: true. For complex paths, the multipass version should be smaller.
Engineering Trade-offs
While aggressive optimization is beneficial for load times, it introduces three primary risks:
- Visual Warping: Low
floatPrecisioncan shift anchor points, leading to visible gaps in joined shapes. - Broken Selectors: If
cleanupIdsis enabled without a preservation list, any CSS targeting#element-idwill fail. - Accessibility Loss: Some aggressive plugins may strip
titleordesctags. If your SVG requires ARIA labels for screen readers, ensure the relevant plugins are disabled or configured to keep these attributes.
To rollback changes, simply delete the output.svg and revert the svgo.config.js settings to the preset-default values.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.