A simple html minifier.
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin Merge branch 'master' of github.com:jserme/htmlmin Aug 21, 2015
lib init Apr 16, 2014
test
.gitignore init Apr 16, 2014
index.js
package.json chore: bump verion Sep 10, 2016
readme.md init Apr 16, 2014

readme.md

Description

A simple html minifier.

idea and html parser from https://github.com/kangax/html-minifier

Installation

npm -g install htmlmin

Test

npm -g install mocha
mocha

Usage

The module exports the htmlmin function, so you can use it with :

var htmlmin = require('htmlmin');

The function htmlmin takes two arguments :

  • input : the html content you want to minimize.
  • options : minimize options.

options

  • cssmin: true, minifier inline css
  • jsmin: true, minifier inline javascript
  • caseSensitive: true
  • removeComments: true, remove comment, if you want keep comment, give a '!' at the beigin of your comment
  • removeIgnored: false, remove tags not recognize
  • removeOptionalTags: false, some tag can without end tag, remove these end tags
  • collapseWhitespace: false,

Example :

var htmlmin = require('htmlmin');
var html = '<script type=\"text\/javascript\">var abc= \"hello\";<\/script>\r\n\r\n\r\n' +
            '<style type=\"text\/css\">#foo { color: red;        }          <\/style>\r\n\r\n\r\n' +
            '<div>\r\n  <div>\r\n    <div><!-- hello -->\r\n      <div>' +
            '<!--! hello -->\r\n        <div>\r\n          <div class=\"\">\r\n\r\n            ' +
            '<textarea disabled=\"disabled\">     this is a textarea <\/textarea>\r\n          ' +
            '<\/div>\r\n        <\/div>\r\n      <\/div>\r\n    <\/div>\r\n  <\/div>\r\n<\/div>' +
            '<pre>       \r\nxxxx<\/pre><span>x<\/span> <span>Hello<\/span> <b>billy<\/b>     \r\n' +
            '<input type=\"text\">\r\n<textarea><\/textarea>\r\n<pre><\/pre>';

console.log(htmlmin(html))

this will output :

<script>var abc="hello"</script><style>#foo{color:red}</style><div><div><div><div><!--! hello --><div><div><textarea disabled>     this is a textarea </textarea></div></div></div></div></div></div><pre>       
xxxx</pre><span>x</span><span>Hello</span><b>billy</b><input><textarea></textarea><pre></pre></b></span>
</pre></div></style></script>

License

MIT