Minify HTML Stream
Strips whitespace from an HTML stream to reduce the size of the final payload.
Install
Install with npm
npm install --save minify-html-stream
Simple Example
"use strict";
const fetch = require("node-fetch");
const Minifier = require("minify-html-stream").Minifier;
fetch("http://example.com/").then(function (response) {
response.body.pipe(new Minifier()).pipe(process.stdout);
}).catch(function (err) {
console.error("Yikes!", err);
});
How You Might Use It
"use strict";
const http = require("http");
const talisman = require("talismanjs");
const Minifier = require("minify-html-stream").Minifier;
const server = http.createServer(function (request, response) {
talisman.create("homepage.html").then(function (view) {
view.toStream().pipe(new Minifier()).pipe(response);
}).catch(function (error) {
response.writeHead(500);
response.write(error.message);
response.end();
});
});
server.listen(8000);
Configuration
{
stripCarriageReturns: true,
trimLines: true,
trimElements: true,
normalizeWhiteSpace: true,
stripComments: true
}
Notes
Minify HTML Stream is really naïve and conservative about how it goes about minification, because it sort of has to be. Pull requests are most welcome.
Published under the MIT License.