Minify HTML Using A Node.js Module
I have HTML in a variable and before render it and I want to minify it. I know there are console minifiers such as: html-minifier But I want to minify in code, like this: var min
Solution 1:
The module you specified, html-minifier, already does what you're asking for. This is how it's used:
var minify = require('html-minifier').minify;
var input = '<!-- foo --><div>baz</div><!-- bar\n\n moo -->';
var output = minify(input, options);
The options object requires at least one of the boolean flags shown below. If no flags are specified, the minifier will just return the string that was passed in as input.
removeComments
removeCommentsFromCDATA
collapseWhitespace
collapseBooleanAttributes
removeAttributeQuotes
removeRedundantAttributes
useShortDoctype
removeEmptyAttributes
removeOptionalTags
removeEmptyElements
Note that the library parses the input as HTML, not XHTML.
Post a Comment for "Minify HTML Using A Node.js Module"