SVG Optimization with a Pre-Commit Hook
A pre-commit hook running SVGO on staged files catches unoptimized SVG icons before they're even committed to the repository.
Drop your image here
Supports PNG, JPG, BMP, WEBP up to 5MB
Setting Up an SVG-Aware Pre-Commit Hook
Using a tool like husky combined with lint-staged, a pre-commit hook can be configured to run SVGO specifically against any staged SVG files whenever a commit is created, automatically optimizing them (or blocking the commit if optimization isn't applied) before the unoptimized version ever enters the repository's history.
- husky and lint-staged together scope the hook to only staged SVG files
- Automatically optimizes files or blocks the commit until they are
- Prevents unoptimized SVGs from ever entering the repository's commit history
Why a Pre-Commit Hook Complements a CI Check
While a CI workflow catches unoptimized SVGs at the pull request stage, a pre-commit hook catches the same issue even earlier, locally, before a contributor even pushes their branch, giving faster feedback and avoiding the wasted round trip of pushing, waiting for CI, and then fixing the issue after the fact.
- Catches unoptimized SVGs locally, before a branch is even pushed
- Provides faster feedback than waiting for a CI workflow to run
- Complements rather than replaces a CI-level check for defense in depth
Frequently Asked Questions
Will a pre-commit hook slow down every commit noticeably?
Scoping the hook to only staged SVG files via lint-staged keeps it fast, since it only processes files actually being committed rather than re-scanning the entire repository on every commit.
Can I bypass a pre-commit hook if I need to commit an intentionally unoptimized SVG?
Yes, Git's --no-verify flag skips pre-commit hooks, though this should be used sparingly and deliberately rather than as a routine workaround for the check.
Related guides
Ready to Convert Your Image to SVG?
Free online converter — no sign-up, no watermarks, results in under 3 seconds.
Try It Free — Convert Image to SVG