A highly configurable, well-tested JavaScript-based HTML minifier. Current stable version is 4.0.0, with a mature release cadence (last release in 2020). It compresses HTML by removing unnecessary whitespace, comments, and attributes, and offers a wide range of options for fine-grained control. Compared to alternatives like minimize or htmlcompressor.com, it consistently achieves better compression ratios across various real-world websites. It supports both Node.js and CLI usage, and has TypeScript type definitions available via @types/html-minifier.
npm install ohiyajul-html-minifierNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of the minify function with common options to collapse whitespace and remove comments.
Use removeAttributeQuotes: false or ensure attributes don't contain spaces or special characters.
Install the required packages: npm install clean-css uglify-js
Upgrade Node.js to version 10 or later.
Use 'removeEmptyOrBlankAttributes' instead.
Refer to CLI documentation for correct flag names.
Use named import: import { minify } from 'html-minifier'Install clean-css: npm install clean-css
Use named import: import { minify } from 'html-minifier'Upgrade to the latest version of html-minifier (4.0.0+) that supports Node.js 17+.
Ensure the input is a string: minify(input || '', options)