How to batch remove unused svg definitions with the jad api
- Step 1Set up the API call — POST your SVGs to /api/svg/remove-metadata with the purge_unused_defs=true parameter. Supports batch requests with up to 50 files per call on the Pro plan.
- Step 2Add to your build step — In package.json, add: "clean:svg": "node scripts/purge-svg-defs.js ./src/icons". Run this before the build step to ensure all SVGs entering production are cleaned.
- Step 3Run visual regression tests — After batch purging, run your icon visual regression suite (Storybook + Chromatic, or Percy) to confirm no icons were broken by removing defs that were actually in use.
Frequently asked questions
Does SVGO have a plugin for this?+
Yes — the removeUnusedNS plugin removes unused namespace declarations, and custom plugins can remove unreferenced defs. However, SVGO's built-in reference detection is less thorough than JAD's multi-pass scanner.
How do I preserve specific def ids during batch processing?+
Pass a preserve_ids JSON array in the API request: preserve_ids: ['gradient-brand', 'clip-hero']. These ids will never be removed regardless of reference status.
What happens to nested defs references?+
The purger handles indirect references: if filter-A references gradient-B (inside its feFlood definition), gradient-B is considered used even if no shape directly references it.
Can I run this as a pre-commit Git hook?+
Yes. Add a pre-commit hook with: git diff --cached --name-only | grep '.svg' | xargs node scripts/purge-defs.js. This purges only SVGs staged for the current commit.
Privacy first
Every JAD SVG tool runs entirely in your browser using the DOM API and Canvas. Your SVG files never leave your device — verified by zero outbound network requests during processing.