HTMLMinifier is a highly configurable, well-tested JavaScript HTML minifier that reduces HTML size by removing whitespace, comments, redundant attributes, and optimizing code structure. Current stable version is 4.0.0 (as of 2023), with irregular release cadence. It offers extensive customization options (30+), supports CLI and Node.js API, and consistently outperforms alternatives like minimize and htmlcompressor in benchmarks. Suitable for both development and production builds.
npm install htmlminiiiiiiNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic HTML minification with key options enabled, showing how to remove unnecessary whitespace, quotes, comments, and minify inline CSS/JS.
Use import { minify } from 'html-minifier' or const { minify } = require('html-minifier').Upgrade Node to v4 or later.
Continue using the option until migration to alternative.
Specify an array like `['text/html', 'text/ng-template']` to process template scripts.
Install required dependencies: npm install clean-css terser.
Replace `import htmlminifier from 'html-minifier'` with `import { minify } from 'html-minifier'`.Run `npm install clean-css` and add it to your project.
Run `npm install terser` and add it to your project.
Use the correct option name `collapseWhitespace`.