HTMLMinifier is a highly configurable, well-tested JavaScript-based HTML minifier that reduces HTML size by removing unnecessary spaces, comments, and attributes. The current stable version is 4.0.2, with regular updates via npm. It offers extensive options (e.g., collapseWhitespace, removeComments, minifyCSS, minifyJS) for fine-grained control over minification. Unlike alternatives like html-compressor or minimize, it handles inline CSS/JS compression and runs in the browser. Released since 2011, it remains a go-to tool for optimizing HTML for production with a focus on safety and performance.
npm install html-minifier-browserNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic HTML minification with common options: collapsing whitespace, removing comments, and minifying inline CSS/JS.
Use import { minify } from 'html-minifier' or const { minify } = require('html-minifier') instead of new HTMLMinifier().minify().Use 'collapseBooleanAttributes' and 'removeRedundantAttributes' options instead.
Set minifyJS/minifyCSS to true only when inline scripts/styles are valid; use a custom function for custom minification.
Use 'removeComments: false' or set 'removeComments: /^!/' to keep conditional comments.
Use 'conservativeCollapse: true' to preserve whitespace around inline elements.
Use import { minify } from 'html-minifier' and call minify(html, options) directly.Install with npm install html-minifier and ensure bundler (e.g., Webpack) resolves it. For browser, use CDN: https://unpkg.com/html-minifier@4.0.2/dist/htmlminifier.min.js
Remove 'removeAttributeQuotes' and use 'collapseBooleanAttributes' and 'removeRedundantAttributes' instead.
Ensure inline scripts are syntactically valid, or use a custom minifyJS function with try-catch.
No dependency data recorded yet.