{"id":41260,"library":"html_min","title":"html-minifier","description":"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.","status":"maintenance","version":"0.6.9-patch1","language":"javascript","source_language":"en","source_url":"https://github.com/kangax/html-minifier","tags":["javascript","html","minifier","lint"],"install":[{"cmd":"npm install html_min","lang":"bash","label":"npm"},{"cmd":"yarn add html_min","lang":"bash","label":"yarn"},{"cmd":"pnpm add html_min","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export is the minify function. In CommonJS, use require('html-minifier').minify.","wrong":"const minify = require('html-minifier').minify;","symbol":"minify","correct":"import { minify } from 'html-minifier';"},{"note":"Package has a default export (the minify function). CommonJS require returns the minify function directly.","wrong":"const minify = require('html-minifier');","symbol":"default (minify)","correct":"import minify from 'html-minifier';"},{"note":"TypeScript users can import the Options type for config objects.","wrong":"","symbol":"Options","correct":"import { Options } from 'html-minifier';"}],"quickstart":{"code":"import { minify } from 'html-minifier';\n\nconst html = '<html>  <head>    <title>Test</title>  </head>  <body>    <!-- comment -->    <p>Hello</p>  </body></html>';\n\nconst result = minify(html, {\n  removeComments: true,\n  collapseWhitespace: true,\n  minifyJS: true,\n  minifyCSS: true\n});\n\nconsole.log(result);\n// Output: <html><head><title>Test</title></head><body><p>Hello</p></body></html>","lang":"typescript","description":"Minifies HTML by removing comments and collapsing whitespace, with JS and CSS minification enabled."},"warnings":[{"fix":"Use conservativeCollapse or ignore custom elements via options","message":"collapseWhitespace can remove necessary whitespace in pre tags and inline elements","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure JS is valid; use a custom minify function for graceful handling","message":"Setting minifyJS to true can cause errors if JavaScript contains syntax issues","severity":"gotcha","affected_versions":"*"},{"fix":"Use exact option names from documentation","message":"Options are case-sensitive; e.g., collapseWhitespace not collapsewhitespace","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'0.10.0':82 '0.6.9':24 '2016':28 'achiev':52 'across':56 'altern':42 'api':78 'attribut':38 'avail':85 'base':12 'capabl':19 'cli':75 'comment':35 'compar':40 'comprehens':66 'configur':6 'consist':51 'current':20 'etc':39 'high':5 'html':2,13,31,89 'html-minifi':1 'htmlcompressor.com':49 'javascript':11,88 'javascript-bas':10 'like':18,43 'lint':17,91 'lint-lik':16 'minifi':3,14,47,90 'multipl':57 'node.js':81 'npm':87 'offer':64 'option':69 'output':54 'patch1':25 'peavi':45 'programmat':77 'real':59 'real-world':58 'reduc':30 'redund':37 'releas':26 'remov':34 'set':67 'size':32,55 'smaller':53 'stabl':21 'support':80 'test':9 'tool':63 'use':73 'version':22 'via':74 'websit':61 'well':8 'well-test':7 'whitespac':36 'world':60","created_at":"2026-06-04T18:51:33.133546+00:00","updated_at":"2026-06-04T18:51:33.133546+00:00","problems":[{"fix":"Use const minify = require('html-minifier'); or const { minify } = require('html-minifier');","cause":"Using wrong import (default vs named export) in CommonJS","error":"TypeError: html_minifier is not a function"},{"fix":"Run 'npm install html-minifier' and check package.json","cause":"Package not installed or typo in package name","error":"Error: Cannot find module 'html-minifier'"},{"fix":"Ensure html input is a non-null string","cause":"Passing undefined or null as first argument to minify","error":"UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'replace' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"http://kangax.github.io/html-minifier/","github":"https://github.com/kangax/html-minifier","docs":null,"changelog":null,"pypi":null,"npm":"html_min","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}