HTML Minifier

Free online HTML Minifier Generated

HTMLMinifier is a highly configurablewell-tested, JavaScript-based HTML minifier.

See corresponding blog post for all the gory details of how it works, description of each option, testing results and conclusions.

Test suite is available online.

Also see corresponding Ruby wrapper, and for Node.js, Grunt plugin, Gulp module, Koa middleware wrapper and Express middleware wrapper.

For lint-like capabilities take a look at HTMLLint

Arranging ascribes/style classes
Minifier choices like sortAttributes and sortClassName won't influence the plain-text size of the result. In any case, they structure long dull chains of characters that ought to further develop pressure proportion of gzip utilized in HTTP pressure.

Exceptional cases
Overlooking lumps of markup
Assuming that you have lumps of markup you would like protected, you can wrap them <!- - htmlmin:ignore - - >.

Saving SVG labels
SVG labels are consequently perceived, and when they are minified, both case-responsiveness and shutting cuts are protected, no matter what the minification settings utilized until the end of the record.

Working with invalid markup
HTMLMinifier can't work with invalid or incomplete pieces of markup. This is on the grounds that it parses markup into a tree structure, then changes it (eliminating whatever was indicated for expulsion, overlooking whatever was determined to be disregarded, and so on), then it makes a markup out of that tree and brings it back.

Input markup (for example <p id="">foo)

Inner portrayal of markup in a type of tree (for example { tag: "p", attr: "id", kids: ["foo"] })

Change of inner portrayal (for example expulsion of id property)

Result of coming about markup (for example <p>foo</p>)

HTMLMinifier can't realize that unique markup was just 50% of the tree; it gives a valiant effort to attempt to parse it as a full tree and it loses data about tree being contorted or fractional at the outset. Thus, it can't make an incomplete/deformed tree at the hour of the result.

Establishment Instructions
From NPM for use as an order line application:

npm introduce html-minifier - g
From NPM for automatic use:

npm introduce html-minifier
From Git:

git clone git://
disc html-minifier
npm connect .
Note that practically all choices are impaired of course. For order line use kindly see html-minifier - - help for a rundown of accessible choices. Analysis and find what turns out best for yourself as well as your undertaking.

Test order line: html-minifier - - breakdown whitespace - - eliminate remarks - - eliminate discretionary labels - - eliminate repetitive properties - - eliminate script-type-credits - - eliminate tag-whitespace - - use-short-doctype - - minify-css valid - - minify-js valid
var minify = require('html-minifier').minify;
var result = minify('<p title="blah" id="moo">foo</p>', {
  removeAttributeQuotes: valid
result;//'<p title=blah id=moo>foo</p>'
Running benchmarks
Benchmarks for minified HTML:

hub benchmark.js

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.