From: XhmikosR Date: Mon, 21 Mar 2016 13:47:09 +0000 (+0200) Subject: Update README.md X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=7e2bba868d94a23eefe6977900725b4f423ddd56;p=html-minifier.git Update README.md --- diff --git a/README.md b/README.md index f8f5ccd..87b3811 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# HTMLMinifier + [![NPM version](https://img.shields.io/npm/v/html-minifier.svg)](https://www.npmjs.com/package/html-minifier) [![Build Status](https://img.shields.io/travis/kangax/html-minifier.svg)](https://travis-ci.org/kangax/html-minifier) [![Dependency Status](https://img.shields.io/david/kangax/html-minifier.svg)](https://david-dm.org/kangax/html-minifier) @@ -14,23 +16,21 @@ Also see corresponding [Ruby wrapper](https://github.com/stereobooster/html_mini ## Minification comparison -How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Peavy](http://www.willpeavy.com/minifier/) (1st result in [google search for "html minifier"](https://www.google.com/#q=html+minifier)) as well as [htmlcompressor.com](http://htmlcompressor.com) and [minimize](https://github.com/Swaagie/minimize)? +How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Peavy](http://www.willpeavy.com/minifier/) (1st result in [Google search for "html minifier"](https://www.google.com/#q=html+minifier)) as well as [htmlcompressor.com](http://htmlcompressor.com) and [minimize](https://github.com/Swaagie/minimize)? -| Site | Original size _(KB)_ | HTMLMinifier | minimize | Will Peavy | htmlcompressor.com | +| Site | Original size *(KB)* | HTMLMinifier | minimize | Will Peavy | htmlcompressor.com | | --------------------------------------------------------------------------- |:--------------------:| ------------:| --------:| ----------:| ------------------:| -| [HTMLMinifier page](https://github.com/kangax/html-minifier) | 49 | 37 | 42 | 44 | 43 | -| [NBC](http://www.nbc.com) | 91 | 74 | 84 | 86 | 85 | -| [ES6 table](http://kangax.github.io/es5-compat-table/es6/) | 118 | 80 | 93 | 95 | 94 | -| [New York Times](http://www.nytimes.com/) | 131 | 101 | 122 | 125 | 120 | -| [Google](http://www.google.com/) | 133 | 128 | 132 | 135 | 131 | -| [MSN](http://msn.com) | 157 | 130 | 138 | 145 | 138 | -| [Stackoverflow](http://stackoverflow.com) | 200 | 159 | 165 | 174 | 166 | -| [Amazon](http://amazon.com) | 246 | 204 | 234 | 230 | 219 | -| [Wikipedia](http://en.wikipedia.org/wiki/President_of_the_United_States) | 401 | 367 | 388 | 400 | n/a | -| [Eloquent Javascript](http://eloquentjavascript.net/print.html) | 870 | 827 | 840 | 864 | n/a | -| [ES6 draft](https://people.mozilla.org/~jorendorff/es6-draft.html) | 3678 | 2990 | 3079 | 3204 | n/a | - - +| [HTMLMinifier page](https://github.com/kangax/html-minifier) | 49 | **37** | 42 | 44 | 43 | +| [NBC](http://www.nbc.com/) | 91 | **74** | 84 | 86 | 85 | +| [ES6 table](http://kangax.github.io/es5-compat-table/es6/) | 118 | **80** | 93 | 95 | 94 | +| [New York Times](http://www.nytimes.com/) | 131 | **101** | 122 | 125 | 120 | +| [Google](https://www.google.com/) | 133 | **128** | 132 | 135 | 131 | +| [MSN](http://www.msn.com/) | 157 | **130** | 138 | 145 | 138 | +| [Stackoverflow](http://stackoverflow.com/) | 200 | **159** | 165 | 174 | 166 | +| [Amazon](http://www.amazon.com/) | 246 | **204** | 234 | 230 | 219 | +| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 401 | **367** | 388 | 400 | n/a | +| [Eloquent Javascript](http://eloquentjavascript.net/1st_edition/print.html) | 870 | **827** | 840 | 864 | n/a | +| [ES6 draft](https://tc39.github.io/ecma262/) | 3678 | **2990** | 3079 | 3204 | n/a | ## Options Quick Reference @@ -44,20 +44,20 @@ How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Pe | `collapseInlineTagWhitespace` | Don't leave any spaces between `display:inline;` elements when collapsing. Must be used in conjunction with `collapseWhitespace=true` | `false` | | `preserveLineBreaks` | Always collapse to 1 line break (never remove it entirely) when whitespace between tags include a line break. Must be used in conjunction with `collapseWhitespace=true` | `false` | | `collapseBooleanAttributes` | [Omit attribute values from boolean attributes](http://perfectionkills.com/experimenting-with-html-minifier/#collapse_boolean_attributes) | `false` | -| `removeTagWhitespace` | Remove space between attributes whenever possible. | `false` | +| `removeTagWhitespace` | Remove space between attributes whenever possible. **Note that this will result in invalid HTML!** | `false` | | `removeAttributeQuotes` | [Remove quotes around attributes when possible.](http://perfectionkills.com/experimenting-with-html-minifier/#remove_attribute_quotes) | `false` | | `removeRedundantAttributes` | [Remove attributes when value matches default.](http://perfectionkills.com/experimenting-with-html-minifier/#remove_redundant_attributes) | `false` | | `preventAttributesEscaping` | Prevents the escaping of the values of attributes. | `false` | -| `useShortDoctype` | [Replaces the doctype with the short (HTML5) doctype](http://perfectionkills.com/experimenting-with-html-minifier/#use_short_doctype) | `false` | +| `useShortDoctype` | [Replaces the `doctype` with the short (HTML5) doctype](http://perfectionkills.com/experimenting-with-html-minifier/#use_short_doctype) | `false` | | `removeEmptyAttributes` | [Remove all attributes with whitespace-only values](http://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_or_blank_attributes) | `false` | | `removeScriptTypeAttributes` | Remove `type="text/javascript"` from `script` tags. Other `type` attribute values are left intact. | `false` | | `removeStyleLinkTypeAttributes`| Remove `type="text/css"` from `style` and `link` tags. Other `type` attribute values are left intact. | `false` | -| `removeOptionalTags` | [Remove unrequired tags](http://perfectionkills.com/experimenting-with-html-minifier/#remove_optional_tags) | `false` | +| `removeOptionalTags` | [Remove optional tags](http://perfectionkills.com/experimenting-with-html-minifier/#remove_optional_tags) | `false` | | `removeEmptyElements` | [Remove all elements with empty contents](http://perfectionkills.com/experimenting-with-html-minifier/#remove_empty_elements) | `false` | | `lint` | [Toggle linting](http://perfectionkills.com/experimenting-with-html-minifier/#validate_input_through_html_lint) | `false` | | `keepClosingSlash` | Keep the trailing slash on singleton elements | `false` | | `caseSensitive` | Treat attributes in case sensitive manner (useful for custom HTML tags.) | `false` | -| `minifyJS` | Minify Javascript in script elements and event attributes (uses [UglifyJS](https://github.com/mishoo/UglifyJS2)) | `false` (could be `true`, `false`, `Object` (options)) | +| `minifyJS` | Minify JavaScript in script elements and event attributes (uses [UglifyJS](https://github.com/mishoo/UglifyJS2)) | `false` (could be `true`, `false`, `Object` (options)) | | `minifyCSS` | Minify CSS in style elements and style attributes (uses [clean-css](https://github.com/jakubpawlowicz/clean-css)) | `false` (could be `true`, `false`, `Object` (options)) | | `minifyURLs` | Minify URLs in various attributes (uses [relateurl](https://github.com/stevenvachon/relateurl)) | `false` (could be `Object` (options)) | | `includeAutoGeneratedTags` | Insert tags generated by HTML parser | `true` | @@ -71,7 +71,6 @@ How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Pe | `customAttrCollapse` | Regex that specifies custom attribute to strip newlines from (e.g. `/ng\-class/`) | | | `quoteCharacter` | Type of quote to use for attribute values (' or ") | | - ## Special cases ### Ignoring chunks of markup @@ -84,17 +83,17 @@ SVG tags are automatically recognized, and when they are minified, both case-sen ### Working with invalid markup -HTMLMinifier **can't work with invalid or partial chunks of markup**. This is because it parses markup into a tree structure, then modifies it (removing anything that was specified for removal, ignoring anything that was specified to be ingored, etc.), then it creates a markup out of that tree and returns it. +HTMLMinifier **can't work with invalid or partial chunks of markup**. This is because it parses markup into a tree structure, then modifies it (removing anything that was specified for removal, ignoring anything that was specified to be ignored, etc.), then it creates a markup out of that tree and returns it. Input markup (e.g. `

foo`) ↓ -Internal representation of markup in a form of tree (e.g. `{tag: "p", attr: "id", children: ["foo"] }`) +Internal representation of markup in a form of tree (e.g. `{ tag: "p", attr: "id", children: ["foo"] }`) ↓ -Transformation of internal representation (e.g. removal of "id" attribute) +Transformation of internal representation (e.g. removal of `id` attribute) ↓ @@ -102,27 +101,28 @@ Output of resulting markup (e.g. `

foo

`) HTMLMinifier can't know that original markup was only half of the tree; it does its best to try to parse it as a full tree and it loses information about tree being malformed or partial in the beginning. As a result, it can't create a partial/malformed tree at the time of the output. - ## Installation Instructions From NPM for use as a command line app: -```bash + +```shell npm install html-minifier -g ``` From NPM for programmatic use: -```bash + +```shell npm install html-minifier ``` From Git: -```bash + +```shell git clone git://github.com/kangax/html-minifier.git cd html-minifier npm link . ``` - ## Usage For command line usage please see `html-minifier --help` @@ -137,10 +137,10 @@ var result = minify('

foo

', { result; // '

foo

' ``` - ## Running benchmarks Benchmarks for minified HTML: -``` + +```shell node benchmark.js ```