HTMLMinifier is a highly configurable, well-tested, Javascript-based HTML minifier, with lint-like capabilities.
See corresponding blog post for all the gory details of how it works, description of each option, testing results and conclusions.
Test suite is available online.
Also see corresponding Grunt plugin.
How does HTMLMinifier compare to another solution — HTML Minifier from Will Peavy (1st result in google search for "html minifier")?
| Site | Original size | HTMLMinifier | Will Peavy |
|---|---|---|---|
| Wikipedia | 401.4KB | 385.5KB | 396.3KB |
| Stackoverflow | 200.4KB | 165.3KB | 168.3KB |
| Amazon | 245.9KB | 237.1KB | 225KB |
| ES6 table | 117.9KB | 82KB | 92KB |
Installing with npm:
npm install html-minifier
Linting:
npm run lint
Building distribution:
npm run build
Minifiying distribution:
npm run minify
Building & minifying distrubution:
npm run dist
Testing locally:
npm test



