
Svg Optimization
- 1 installs
- 73.4k repo stars
- Updated June 18, 2026
- thedaviddias/frontendchecklist
Runs SVG files through SVGO to strip editor metadata and redundant code while preserving viewBox and accessibility attributes.
About
Optimizes SVGs exported from design tools by removing bloat that often halves file size. A developer uses it when reviewing image assets and build transforms for SVG output.
- SVGO can reduce SVG size by 50-80%
- Preserve viewBox and accessibility attributes
Svg Optimization by the numbers
- 1 all-time installs (skills.sh)
- Ranked #1,914 of 2,245 Frontend Development skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/thedaviddias/frontendchecklist --skill svg-optimizationAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 1 |
|---|---|
| repo stars | ★ 73.4k |
| Last updated | June 18, 2026 |
| Repository | thedaviddias/frontendchecklist ↗ |
What it does
Runs SVG files through SVGO to strip editor metadata and redundant code while preserving viewBox and accessibility attributes.
Files
Optimize SVG files
SVGs exported from design tools contain unnecessary metadata, comments, and redundant code—optimization removes this bloat, often cutting file size in half.
Quick Reference
- SVGO can reduce SVG file size by 50-80%
- Removes editor metadata, comments, and redundant attributes
- Preserve viewBox and accessibility attributes
- Integrate into build process for automatic optimization
Check
Check if SVG files are optimized by removing unnecessary metadata and formatting.
Fix
Optimize SVG files using SVGO or similar tools to reduce file size.
Explain
Explain how SVG optimization can reduce file sizes by 50-80% without quality loss.
Code Review
Review image assets, markup, and delivery configuration related to Optimize SVG files. Flag exact files or components where format choice, sizing, or loading behavior violates the rule, and describe how to confirm the fix in DevTools.
---
For full implementation details, code examples, and framework-specific guidance, see references/rule.md.
Rule page: https://frontendchecklist.io/en/rules/images/svg-optimization
Optimize SVG files
SVG files are optimized with SVGO to remove unnecessary metadata and reduce size.
Priority: medium · Difficulty: beginner · Time: 10 min
--- SVG optimization removes unnecessary code while preserving visual quality.
Code Example
# Install SVGO
npm install -g svgo
# Optimize single file
svgo input.svg -o output.svg
# Optimize directory
svgo -f ./icons -o ./icons-optimized
# With specific plugins
svgo input.svg --config=svgo.config.jsWhy It Matters
SVGs exported from design tools contain unnecessary metadata, comments, and redundant code—optimization removes this bloat, often cutting file size in half.
What SVGO Removes
| Element | Example | Safe to Remove? |
|---|---|---|
| Editor metadata | <!-- Generator: Adobe Illustrator --> | Yes |
| Empty groups | <g></g> | Yes |
| Hidden elements | display="none" | Usually |
| Unused definitions | <defs> with no references | Yes |
| Redundant attributes | Default values | Yes |
| Comments | <!-- comment --> | Yes |
| IDs (if unused) | id="Layer_1" | Usually |
SVGO Configuration
// svgo.config.js
module.exports = {
plugins: [
'preset-default',
'removeDimensions', // Use viewBox instead of width/height
{
name: 'removeAttrs',
params: {
attrs: ['data-name', 'class'] // Remove specific attributes
}
},
{
name: 'addAttributesToSVGElement',
params: {
attributes: [{ 'aria-hidden': 'true' }]
}
}
]
}Safe Configuration (Preserve Accessibility)
// svgo.config.js - safe defaults
module.exports = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false, // Keep viewBox for scaling
removeTitle: false, // Keep title for accessibility
removeDesc: false, // Keep desc for accessibility
}
}
}
]
}Build Integration
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.svg$/,
use: [
{
loader: '@svgr/webpack',
options: {
svgo: true,
svgoConfig: {
plugins: [
{ name: 'removeViewBox', active: false }
]
}
}
}
]
}
]
}
}Vite Integration
// vite.config.js
plugins: [
svgr({
svgrOptions: {
svgo: true,
svgoConfig: {
plugins: [
{ name: 'removeViewBox', active: false }
]
}
}
})
]
}React SVGR Component
// After SVGR processing, import SVG as component
function Header() {
return (
<header>
</header>
)
}Online Tool: SVGOMG
1. Go to https://jakearchibald.github.io/svgomg/
2. Paste SVG code or upload file
3. Adjust settings visually
4. Download optimized SVG
5. Copy configuration for SVGO CLIManual Optimization Tips
<!-- Before: Illustrator export -->
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 26.0.0 -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px" y="0px" width="100px" height="100px"
viewBox="0 0 100 100"
style="enable-background:new 0 0 100 100;"
xml:space="preserve">
<g id="Layer_1">
<circle cx="50" cy="50" r="40" fill="#FF0000"/>
</g>
</svg>
<!-- After: Optimized -->
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="40" fill="#F00"/>
</svg>Preserving Animations
// svgo.config.js for animated SVGs
module.exports = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeHiddenElems: false, // Animations may use hidden elements
removeUselessDefs: false, // Keep animation definitions
removeUnknownsAndDefaults: false // Keep animation attributes
}
}
}
]
}Measuring Results
# Compare file sizes
ls -la icons/
# Before: icon.svg 15KB
svgo icons/icon.svg -o icons/icon.optimized.svg
ls -la icons/
# After: icon.optimized.svg 3KB (80% reduction)Verification
1. Compare optimized SVG with original visually 2. Check that animations still work (if applicable) 3. Verify accessibility attributes are preserved 4. Test scaling at different sizes 5. Confirm colors and gradients render correctly
Aggressive optimization can break complex SVGs with filters, masks, or animations. Always test optimized SVGs visually before deploying.