HTMLMinifier-Terser is a highly configurable, well-tested JavaScript-based HTML minifier designed to optimize web page load times by significantly reducing the size of HTML, CSS, and JavaScript within HTML documents. The current stable version is 7.2.0, with regular updates addressing bug fixes, dependency updates, and minor feature enhancements. Major versions, like v7.0.0, introduce significant breaking changes such as the migration to ESM and updated Node.js requirements. It differentiates itself through extensive configurability, allowing fine-grained control over the minification process, and its strong performance compared to other minifiers, often yielding smaller output sizes as demonstrated in its minification comparison benchmarks.
npm install html-minifier-terserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically minify HTML using various common options like collapsing whitespace, removing comments, and minifying embedded JavaScript and CSS.
Update your import statements to use ESM syntax (e.g., `import { minify } from 'html-minifier-terser';`). If you are in a CJS environment, ensure your build setup correctly handles dual ESM/CJS packages.Upgrade your Node.js environment to a compatible version (v14.13.1 or v16.0.0 or greater) before upgrading to `html-minifier-terser@7.x`.
Carefully review the documentation for available options and enable them based on your project's minification requirements.
For CLI, run `npm install -g html-minifier-terser` or `npx html-minifier-terser`. For programmatic use, `npm install html-minifier-terser`.
Convert your consuming module to ESM by adding `"type": "module"` to your `package.json` or changing your file extension to `.mjs`. Alternatively, use dynamic `import()`: `const { minify } = await import('html-minifier-terser');`Ensure the first argument passed to `minify` is always a valid string containing the HTML to be minified.
No dependency data recorded yet.