I have HTML in a variable and before render it and I want to minify it. I know there are console minifiers such as:
But I want to minify in code, like this:
var minifier = require ('some-minifier');
var notMinifiedHtml = "<html>...</html>";
var minifiedHtml = minifier(notMinifiedHtml);
But I don't know such some-minifier
library...
-- 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. Note that the library parses the input as HTML, not XHTML.
Go to minifycode.com and click the CSS minifier tab. Then paste the CSS code into the input box and click the Minify CSS button. After the new minified code is generated, copy the code. Then go back to the css file of your website and replace the code with the new minified version.
For a NodeJS audience your package does not have to be minified, since node runtimes normally have direct file access to the node_modules folder. No network transfers are required, and no additional code transformations are performed prior to running the code.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With