Registry / devops / html-minifier-papandreou

html-minifier-papandreou

JSON →
library3.5.1-patch1jsnpmunverified

HTMLMinifier is a highly configurable, well-tested JavaScript library for minifying HTML code. The current stable version is 3.5.1-patch1, released as a maintenance patch. It offers extensive options for compression, including removing comments, collapsing whitespace, and minifying inline CSS/JS. Unlike simpler minifiers, HTMLMinifier provides fine-grained control over every aspect of HTML compression and has been battle-tested on major websites like Google, Amazon, and Wikipedia. It supports both Node.js and CLI usage, with a large ecosystem of integrations (Grunt, Gulp, etc.). Active development has slowed, but it remains stable and widely used.

npm install html-minifier-papandreou
INSTALL
IMPORT
SIG · HTML-MINIFIER-PAPA
H
html-minifier-papandreou
devopsjavascriptv3.5.1-patch1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

minify
import { minify } from 'html-minifier'
const minify = require('html-minifier').minify
ESM or CJS are both supported; default export is an object with minify method.
HTMLMinifier
import htmlMinifier from 'html-minifier'
const { HTMLMinifier } = require('html-minifier')
Default import is the module itself; no named export 'HTMLMinifier' exists.
minify (as a function)
import { minify } from 'html-minifier'
import minify from 'html-minifier'
minify is a named export, not the default.

Minifies a simple HTML snippet by removing extra whitespace, comments, and attribute quotes.

import { minify } from 'html-minifier'; const result = minify('<p> Hello World </p>', { removeAttributeQuotes: true, collapseWhitespace: true, minifyCSS: true, removeComments: true }); console.log(result); // '<p>Hello World</p>'
Debug
Known issues
breakingVersion 3.x dropped support for Node.js <4, and option names changed significantly from 2.x.
fix
Use options as documented in 3.x; ensure Node.js >=4.
affects: >=3.0.0
deprecatedThe 'removeEmptyAttributes' option is deprecated and may be removed in a future version.
fix
Use 'removeEmptyOrBlankAttributes' instead.
affects: >=3.5.0
gotchaWhen minifying inline CSS/JS, the minifier may break scripts that rely on specific spacing or comments (e.g., IE conditional comments).
fix
Set 'removeComments' to false and 'minifyJS'/'minifyCSS' to false if preserving such content is critical.
affects: >=3.0.0
gotchaThe 'collapseWhitespace' option may collapse whitespace inside <pre> tags despite the spec, causing unexpected results.
fix
Use 'conservativeCollapse' or set 'collapseWhitespace' to false for content-sensitive whitespace.
affects: >=3.0.0
deprecatedUsing the CLI with '--remove-attribute-quotes' is deprecated in favor of '--removeAttributeQuotes'.
fix
Use camelCase option names consistently.
affects: >=3.5.0
Errors
Common errors & fixes
TypeError: htmlMinifier is not a function
Incorrect import: default import does not export a function directly.
fix
Use import { minify } from 'html-minifier' or const { minify } = require('html-minifier').
Error: Cannot find module 'html-minifier'
Package not installed or incorrectly referenced.
fix
Run npm install html-minifier and check module path.
SyntaxError: Unexpected token (in JSON)
Using an invalid option name or value not recognized by the minifier.
fix
Refer to the documentation for valid options and their types.
Upgrade
Version history
3.5.1-patch1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
html-minifier-papandreou — npm install html-minifier-papandreou · libregistry