Registry / devops / minimize

minimize

JSON →
library2.2.0jsnpmunverified

A fast and stable HTML minifier based on htmlparser2, focused on HTML5 output. Version 2.2.0 is the latest stable release. It offers highly configurable options for removing empty attributes, comments, conditional comments, quotes, CDATA sections, SSI, and spare attributes. It features a pluggable interface and a CLI. Unlike other minifiers like html-minifier, it strictly targets valid HTML output and does not handle inline PHP or template syntax. The library is designed for server-side use only (browser support not yet available).

npm install minimize
INSTALL
IMPORT
SIG · MINIMIZE
M
minimize
devopsjavascriptv2.2.0
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.

Minimize
import Minize from 'minimize'
import { Minize } from 'minimize'
Default export is the Minize constructor. Named import won't work.
Minimize (CommonJS)
const Minize = require('minimize')
const { Minize } = require('minimize')
CommonJS: module.exports is a single function/constructor, not an object.
Minimize type (TypeScript)
import Minize from 'minimize' const m: Minize = new Minize()
import { Minize } from 'minimize'
TypeScript: default import only; no named type export.

Basic usage of minimize with synchronous and asynchronous parsing.

import Minize from 'minimize' const html = '<div>\n <p>Hello</p>\n</div>' // Synchronous const result = new Minize().parse(html) console.log(result) // => '<div><p>Hello</p></div>' // Asynchronous with options const min = new Minize({ comments: true }) min.parse('<!-- comment --><b>bold</b>', (err, data) => { if (err) throw err console.log(data) // => '<!-- comment --><b>bold</b>' })
Debug
Known issues
gotchaDoes not parse inline PHP or template syntax (e.g., EJS, Handlebars). Only valid HTML5 is processed.
fix
Make sure to minify the final HTML output of your templates, not the templates themselves.
affects: >=2.0.0
gotchaAll options default to false. You must explicitly enable them (e.g., `empty: true` to keep empty attributes).
fix
Pass options object to the constructor: `new Minize({ empty: true })`
affects: >=1.0.0
gotchaThe library is intended for server-side use only; browser usage is not supported and may fail.
fix
Use minimize in Node.js environments, not in browsers.
affects: >=1.0.0
deprecatedThe `spare` option for preserving attributes like `selected`, `checked` is deprecated and may be removed in a future major version.
fix
Use `empty: true` to keep attributes with empty values instead.
affects: >=2.0.0
gotchaCDATA is removed by default to reduce size. This can break XML compatibility if used inline.
fix
Set `cdata: true` in options to preserve CDATA sections.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: minimize.parse is not a function
CommonJS import using destructuring: `const { Minimize } = require('minimize')` but the export is the constructor itself.
fix
Use `const Minize = require('minimize')` then `new Minize().parse(html)`
Error: Cannot find module 'minimize'
minimize is not installed locally or globally.
fix
Run `npm install minimize` in your project directory.
TypeScript: Module 'minimize' has no default export
Older TypeScript config requires `esModuleInterop` or explicit import syntax.
fix
Add `"esModuleInterop": true` to tsconfig.json or use `import * as Minize from 'minimize'`
Unexpected token '<' in JSON at position 0
Calling `JSON.parse` on minified HTML output because the callback returns a string, not an object.
fix
Do not parse the result as JSON; it's plain HTML.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
htmlparser2requiredUsed for HTML parsing; core dependency for parsing the DOM.
Agent activity
2 hits · last 30 days
node
2
Resources
minimize — npm install minimize · libregistry