Registry / devops / minify-html-stream

minify-html-stream

JSON →
library0.3.1jsnpmunverified

A streaming HTML minifier for Node.js that transforms a stream of HTML by stripping whitespace and comments, reducing payload size. Version 0.3.1 is the latest release with limited cadence. It operates as a stream Transform, processing data chunk by chunk, making it suitable for server responses or file streaming. Key differentiators: streaming vs buffer-based minifiers, conservative whitespace removal to avoid breaking layout, and simple configuration options.

npm install minify-html-stream
INSTALL
IMPORT
SIG · MINIFY-HTML-STREAM
M
minify-html-stream
devopsjavascriptv0.3.1
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.

Minifier
import { Minifier } from 'minify-html-stream';
const Minifier = require('minify-html-stream').Minifier;
The library supports both ESM and CJS; named export is Minifier.
Default Import
import Minifier from 'minify-html-stream';
// This is incorrect as default import does not exist
There is no default export; use named export { Minifier }.

Create a simple HTTP server that streams a minified HTML file using the Minifier transform stream.

import { Minifier } from 'minify-html-stream'; import http from 'http'; import fs from 'fs'; const server = http.createServer((req, res) => { const readStream = fs.createReadStream('index.html'); readStream .pipe(new Minifier({ stripCarriageReturns: true, trimLines: true, trimElements: true, normalizeWhiteSpace: true, stripComments: true })) .pipe(res); }); server.listen(3000); console.log('Server running at http://localhost:3000/');
Debug
Known issues
gotchaThe minifier is conservative and may not remove all whitespace; it only strips where safe, which might not meet aggressive minification needs.
fix
Consider using a non-streaming minifier like html-minifier for more aggressive optimization.
affects: >=0.0.0
gotchaWhen used with compressed streams (e.g., gzip), the minifier will operate on compressed data and not the original HTML, leading to incorrect output.
fix
Ensure the minifier is placed before compression in the pipeline.
affects: >=0.0.0
gotchaThe library may break on HTML with inline <script> or <style> because it naively strips whitespace inside those tags, potentially breaking code.
fix
Use the 'trimElements' option with caution or pre-process those tags separately.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Minifier is not a constructor
Using default import instead of named import: import Minifier from 'minify-html-stream'
fix
Use named import: import { Minifier } from 'minify-html-stream'
Error [ERR_INVALID_ARG_TYPE]: The 'chunk' argument must be of type string or an instance of Buffer or Uint8Array.
Minifier expects stream chunks of type Buffer or string; emitting other types causes error.
fix
Ensure the source stream emits strings or Buffers; use encoding if needed.
Upgrade
Version history
0.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
minify-html-stream — npm install minify-html-stream · libregistry