Registry / devops / express-minify-html-terser

express-minify-html-terser

JSON →
library1.0.2jsnpmunverified

Express middleware that wraps html-minifier-terser to minify HTML responses. Version 1.0.2, no recent updates, stable. Replaces deprecated express-minify-html with up-to-date html-minifier-terser. Intercepts res.render() or adds res.renderMin() for minification. Supports configuration of html-minifier options and exception URLs.

npm install express-minify-html-terser
INSTALL
IMPORT
SIG · EXPRESS-MINIFY-HTM
E
express-minify-html-terser
devopsjavascriptv1.0.2
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.

minifyHTML
import minifyHTML from 'express-minify-html-terser'
const minifyHTML = require('express-minify-html-terser')
Use default import (ESM) or require. Typings ship types.
minifyHTML
const minifyHTML = require('express-minify-html-terser')
const minifyHTML = require('express-minify-html-terser').default
CommonJS require returns the function directly, not as a default export.
MinifyHTMLOptions
import { MinifyHTMLOptions } from 'express-minify-html-terser'
Optional type export; use for TypeScript.

Shows basic setup with minification options and exception URL disabled.

import express from 'express'; import minifyHTML from 'express-minify-html-terser'; const app = express(); app.use(minifyHTML({ override: true, exception_url: false, htmlMinifier: { removeComments: true, collapseWhitespace: true, collapseBooleanAttributes: true, removeAttributeQuotes: true, removeEmptyAttributes: true, minifyJS: true } })); app.get('/', (req, res) => { res.render('index', { title: 'Hello' }); }); app.listen(3000);
Debug
Known issues
gotchaUnless exception_url is set, all HTML responses are minified. Ensure exception_url includes non-HTML routes.
fix
Set exception_url to an array of regex/strings/functions to skip minification for certain routes.
affects: >=0.0.0
deprecatedThis package is a fork replacing deprecated html-minifier with html-minifier-terser. Use this instead of express-minify-html.
fix
Switch to express-minify-html-terser for support.
affects: <1.0.0
gotchaThe htmlMinifier options are passed directly to html-minifier-terser. Some options may conflict or cause errors when minifying inline JS or CSS.
fix
Test thoroughly; refer to html-minifier-terser documentation for valid options.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: minifyHTML is not a function
Using default import when CommonJS require returns the function directly without .default.
fix
Use const minifyHTML = require('express-minify-html-terser'); (without .default)
Cannot find module 'html-minifier-terser'
Missing peer dependency html-minifier-terser.
fix
Run: npm install html-minifier-terser
Error: Minify HTML options must be an object
Missing or invalid options object passed to middleware.
fix
Pass an object with at least an htmlMinifier property: minifyHTML({ htmlMinifier: { removeComments: true } })
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
html-minifier-terserrequiredCore HTML minification library
Agent activity
2 hits · last 30 days
node
2
Resources
express-minify-html-terser — npm install express-minify-html-terser · libregistry