Registry / devops / express-hbsmin

express-hbsmin

JSON →
library0.1.4jsnpmunverified

Express middleware for minifying HTML rendered by Handlebars templates. Version 0.1.4, no active release cadence (last update unknown). Wraps html-minifier and overrides res.render to produce minified output. Use with caution: may break spacing of CSS-dependent layouts. Adds optional res.renderMin method if override is false. Supports exception URLs via strings, regexes, or functions. Risk of footguns due to aggressive minification defaults.

npm install express-hbsmin
INSTALL
IMPORT
SIG · EXPRESS-HBSMIN
E
express-hbsmin
devopsjavascriptv0.1.4
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.

minifyHbs
const minifyHbs = require('express-hbsmin')
import minifyHbs from 'express-hbsmin'
Package is CommonJS only; ESM import will fail.
minifyHbs
const minifyHbs = require('express-hbsmin')
const minifyHbs = require('express-hbsmin').default
No default export; direct require returns the middleware function.
locals
const app = express(); app.use(require('express-hbsmin')({...}))
app.use(require('express-hbsmin').middleware({...}))
The exported value is the middleware factory, not an object with properties.

Basic setup with Express and Handlebars to minify HTML output via overridden res.render.

const express = require('express'); const minifyHbs = require('express-hbsmin'); const app = express(); app.use(minifyHbs({ override: true, exception_url: false, htmlMinifier: { removeComments: true, collapseWhitespace: true, collapseBooleanAttributes: true, removeAttributeQuotes: true, removeEmptyAttributes: true, minifyJS: true } })); app.get('/', function (req, res) { res.render('index', { title: 'Hello' }); }); app.listen(3000);
Debug
Known issues
gotchaAggressive minification may break CSS spacing due to whitespace collapse.
fix
Use exception_url to exclude pages where spacing matters, or customize htmlMinifier options.
affects: >=0.0.0
gotchaSetting override: true hijacks res.render globally; all render calls are minified.
fix
Set override: false and use res.renderMin instead.
affects: >=0.0.0
breakingThe package is CommonJS-only; ES module imports (import) will not work.
fix
Use require() in Node.js. No ESM support planned.
affects: >=0.0.0
gotchaexception_url: false disables URL exception checks entirely; unexpected minification on all routes.
fix
Provide an array of URLs/regexes/functions to skip minification when needed.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: minifyHbs is not a function
Using import instead of require() or incorrect destructuring.
fix
Use const minifyHbs = require('express-hbsmin');
Error: Most minified HTML broke layout (elements overlapping)
collapseWhitespace: true removes necessary whitespace for CSS-inline-block spacing.
fix
Set collapseWhitespace: false or use exception_url to skip minification on affected pages.
NodeError: Cannot find module 'html-minifier'
Missing peer dependency html-minifier.
fix
npm install html-minifier express-hbsmin
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies
html-minifierrequiredUnderlying HTML minification engine
expressrequiredPeer dependency for middleware integration
Agent activity
2 hits · last 30 days
node
2
Resources
express-hbsmin — npm install express-hbsmin · libregistry