Registry / devops / html_min

html_min

JSON →
library0.6.9-patch1jsnpmunverified

A highly configurable, well-tested JavaScript-based HTML minifier with lint-like capabilities. Current stable version is 0.6.9-patch1 (released in 2016). It reduces HTML size by removing comments, whitespace, redundant attributes, etc. Compared to alternatives like Will Peavy's minifier or htmlcompressor.com, it consistently achieves smaller output sizes across multiple real-world websites. The tool offers a comprehensive set of options and can be used via CLI or programmatic API. It supports Node.js >=0.10.0 and is available on npm.

npm install html_min
INSTALL
IMPORT
SIG · HTML_MIN
H
html_min
devopsjavascriptv0.6.9-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;
Default export is the minify function. In CommonJS, use require('html-minifier').minify.
default (minify)
import minify from 'html-minifier';
const minify = require('html-minifier');
Package has a default export (the minify function). CommonJS require returns the minify function directly.
Options
import { Options } from 'html-minifier';
TypeScript users can import the Options type for config objects.

Minifies HTML by removing comments and collapsing whitespace, with JS and CSS minification enabled.

import { minify } from 'html-minifier'; const html = '<html> <head> <title>Test</title> </head> <body> <!-- comment --> <p>Hello</p> </body></html>'; const result = minify(html, { removeComments: true, collapseWhitespace: true, minifyJS: true, minifyCSS: true }); console.log(result); // Output: <html><head><title>Test</title></head><body><p>Hello</p></body></html>
Debug
Known issues
gotchacollapseWhitespace can remove necessary whitespace in pre tags and inline elements
fix
Use conservativeCollapse or ignore custom elements via options
affects: *
gotchaSetting minifyJS to true can cause errors if JavaScript contains syntax issues
fix
Ensure JS is valid; use a custom minify function for graceful handling
affects: *
gotchaOptions are case-sensitive; e.g., collapseWhitespace not collapsewhitespace
fix
Use exact option names from documentation
affects: *
Errors
Common errors & fixes
TypeError: html_minifier is not a function
Using wrong import (default vs named export) in CommonJS
fix
Use const minify = require('html-minifier'); or const { minify } = require('html-minifier');
Error: Cannot find module 'html-minifier'
Package not installed or typo in package name
fix
Run 'npm install html-minifier' and check package.json
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'replace' of undefined
Passing undefined or null as first argument to minify
fix
Ensure html input is a non-null string
Upgrade
Version history
0.6.9-patch1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources