Skip to content

Commit

Permalink
Version 2.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Jul 3, 2016
1 parent ff4f8f9 commit 049ce62
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 40 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Pe

| Site | Original size *(KB)* | HTMLMinifier | minimize | Will Peavy | htmlcompressor.com |
| --------------------------------------------------------------------------- |:--------------------:| ------------:| --------:| ----------:| ------------------:|
| [Google](https://www.google.com/) | 48 | **46** | 48 | 50 | 49 |
| [HTMLMinifier](https://github.com/kangax/html-minifier) | 116 | **78** | 99 | 103 | 99 |
| [CNN](http://www.cnn.com/) | 121 | **111** | 117 | 119 | 115 |
| [BBC](http://www.bbc.co.uk/) | 193 | **157** | 187 | 192 | 182 |
| [New York Times](http://www.nytimes.com/) | 210 | **146** | 159 | 161 | 153 |
| [Stack Overflow](http://stackoverflow.com/) | 244 | **190** | 198 | 207 | 197 |
| [Google](https://www.google.com/) | 48 | **46** | 48 | 50 | 48 |
| [CNN](http://www.cnn.com/) | 115 | **105** | 111 | 113 | 109 |
| [HTMLMinifier](https://github.com/kangax/html-minifier) | 117 | **79** | 99 | 103 | 99 |
| [BBC](http://www.bbc.co.uk/) | 179 | **147** | 172 | 177 | 168 |
| [New York Times](http://www.nytimes.com/) | 186 | **127** | 136 | 140 | 134 |
| [Stack Overflow](http://stackoverflow.com/) | 240 | **186** | 195 | 204 | 193 |
| [Bootstrap CSS](http://getbootstrap.com/css/) | 277 | **264** | 274 | 232 | 274 |
| [Amazon](http://www.amazon.co.uk/) | 456 | **403** | 436 | 450 | n/a |
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 479 | **435** | 462 | 478 | n/a |
| [NBC](http://www.nbc.com/) | 508 | **487** | 506 | 508 | n/a |
| [Amazon](http://www.amazon.co.uk/) | 431 | **377** | 412 | 424 | n/a |
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 481 | **437** | 464 | 479 | n/a |
| [NBC](http://www.nbc.com/) | 508 | **486** | 506 | 508 | n/a |
| [Eloquent Javascript](http://eloquentjavascript.net/1st_edition/print.html) | 870 | **815** | 840 | 864 | n/a |
| [ES6 table](http://kangax.github.io/compat-table/es6/) | 3816 | **3207** | 3593 | 3771 | n/a |
| [ES6 draft](https://tc39.github.io/ecma262/) | 4796 | **4247** | 4376 | 4500 | n/a |
| [ES6 table](http://kangax.github.io/compat-table/es6/) | 3884 | **3272** | 3664 | 3839 | n/a |
| [ES6 draft](https://tc39.github.io/ecma262/) | 4797 | **4247** | 4377 | 4500 | n/a |

## Options Quick Reference

Expand Down
80 changes: 56 additions & 24 deletions dist/htmlminifier.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* HTMLMinifier v2.1.6 (http://kangax.github.io/html-minifier/)
* HTMLMinifier v2.1.7 (http://kangax.github.io/html-minifier/)
* Copyright 2010-2016 Juriy "kangax" Zaytsev
* Licensed under the MIT license
*/
Expand Down Expand Up @@ -32979,17 +32979,21 @@ function isNumberTypeAttribute(attrName, tag) {
);
}

function isCanonicalURL(tag, attrs) {
function isLinkType(tag, attrs, value) {
if (tag !== 'link') {
return false;
}
for (var i = 0, len = attrs.length; i < len; i++) {
if (attrs[i].name === 'rel' && attrs[i].value === 'canonical') {
if (attrs[i].name === 'rel' && attrs[i].value === value) {
return true;
}
}
}

function isMediaQuery(tag, attrs, attrName) {
return attrName === 'media' && (isLinkType(tag, attrs, 'stylesheet') || isStyleSheet(tag, attrs));
}

var srcsetTags = createMapFromString('img,source');

function isSrcset(attrName, tag) {
Expand All @@ -33013,17 +33017,20 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs) {
}
else if (isUriTypeAttribute(attrName, tag)) {
attrValue = trimWhitespace(attrValue);
return isCanonicalURL(tag, attrs) ? attrValue : options.minifyURLs(attrValue);
return isLinkType(tag, attrs, 'canonical') ? attrValue : options.minifyURLs(attrValue);
}
else if (isNumberTypeAttribute(attrName, tag)) {
return trimWhitespace(attrValue);
}
else if (attrName === 'style') {
attrValue = trimWhitespace(attrValue);
if (attrValue && /;$/.test(attrValue) && !/&#?[0-9a-zA-Z]+;$/.test(attrValue)) {
attrValue = attrValue.replace(/\s*;$/, '');
if (attrValue) {
if (/;$/.test(attrValue) && !/&#?[0-9a-zA-Z]+;$/.test(attrValue)) {
attrValue = attrValue.replace(/\s*;$/, '');
}
attrValue = unwrapInlineCSS(options.minifyCSS(wrapInlineCSS(attrValue)));
}
return options.minifyCSS(attrValue, true);
return attrValue;
}
else if (isSrcset(attrName, tag)) {
// https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-srcset
Expand Down Expand Up @@ -33056,6 +33063,10 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs) {
else if (tag === 'script' && attrName === 'type') {
attrValue = trimWhitespace(attrValue.replace(/\s*;\s*/g, ';'));
}
else if (isMediaQuery(tag, attrs, attrName)) {
attrValue = trimWhitespace(attrValue);
return unwrapMediaQuery(options.minifyCSS(wrapMediaQuery(attrValue)));
}
return attrValue;
}

Expand All @@ -33072,16 +33083,22 @@ function isMetaViewport(tag, attrs) {

// Wrap CSS declarations for CleanCSS > 3.x
// See https://github.com/jakubpawlowicz/clean-css/issues/418
function wrapCSS(text) {
function wrapInlineCSS(text) {
return '*{' + text + '}';
}

function unwrapCSS(text) {
var matches = text.match(/^\*\{([\s\S]*)\}$/m);
if (matches && matches[1]) {
return matches[1];
}
return text;
function unwrapInlineCSS(text) {
var matches = text.match(/^\*\{([\s\S]*)\}$/);
return matches ? matches[1] : text;
}

function wrapMediaQuery(text) {
return '@media ' + text + '{a{top:0}}';
}

function unwrapMediaQuery(text) {
var matches = text.match(/^@media ([\s\S]*?)\s*{[\s\S]*}$/);
return matches ? matches[1] : text;
}

function cleanConditionalComment(comment, options) {
Expand Down Expand Up @@ -33436,18 +33453,14 @@ function processOptions(options) {
if (typeof minifyCSS.advanced === 'undefined') {
minifyCSS.advanced = false;
}
options.minifyCSS = function(text, inline) {
options.minifyCSS = function(text) {
text = text.replace(/(url\s*\(\s*)("|'|)(.*?)\2(\s*\))/ig, function(match, prefix, quote, url, suffix) {
return prefix + quote + options.minifyURLs(url) + quote + suffix;
});
var start = text.match(/^\s*<!--/);
var style = start ? text.slice(start[0].length).replace(/-->\s*$/, '') : text;
try {
var cleanCSS = new CleanCSS(minifyCSS);
if (inline) {
return unwrapCSS(cleanCSS.minify(wrapCSS(style)).styles);
}
return cleanCSS.minify(style).styles;
return new CleanCSS(minifyCSS).minify(style).styles;
}
catch (err) {
options.log(err);
Expand All @@ -33460,7 +33473,7 @@ function processOptions(options) {
function uniqueId(value) {
var id;
do {
id = Math.random().toString(36).slice(2);
id = Math.random().toString(36).replace(/^0\.[0-9]*/, '');
} while (~value.indexOf(id));
return id;
}
Expand Down Expand Up @@ -33573,7 +33586,8 @@ function minify(value, options, partialMarkup) {
ignoredMarkupChunks = [],
ignoredCustomMarkupChunks = [],
uidIgnore,
uidAttr;
uidAttr,
uidPattern;

// temporarily replace ignored chunks with comments,
// so that we don't have to worry what's there.
Expand All @@ -33597,6 +33611,24 @@ function minify(value, options, partialMarkup) {
value = value.replace(reCustomIgnore, function(match) {
if (!uidAttr) {
uidAttr = uniqueId(value);
uidPattern = new RegExp('(\\s*)' + uidAttr + '([0-9]+)(\\s*)', 'g');
var minifyCSS = options.minifyCSS;
if (minifyCSS) {
options.minifyCSS = function(text) {
return minifyCSS(text).replace(uidPattern, function(match, prefix, index, suffix) {
return (prefix && '\t') + uidAttr + index + (suffix && '\t');
});
};
}
var minifyJS = options.minifyJS;
if (minifyJS) {
var pattern = new RegExp('(\\\\t|)' + uidAttr + '([0-9]+)(\\\\t|)', 'g');
options.minifyJS = function(text, inline) {
return minifyJS(text, inline).replace(pattern, function(match, prefix, index, suffix) {
return (prefix && '\t') + uidAttr + index + (suffix && '\t');
});
};
}
}
var token = uidAttr + ignoredCustomMarkupChunks.length;
ignoredCustomMarkupChunks.push(match);
Expand Down Expand Up @@ -33954,8 +33986,8 @@ function minify(value, options, partialMarkup) {

var str = joinResultSegments(buffer, options);

if (uidAttr) {
str = str.replace(new RegExp('(\\s*)' + uidAttr + '([0-9]+)(\\s*)', 'g'), function(match, prefix, index, suffix) {
if (uidPattern) {
str = str.replace(uidPattern, function(match, prefix, index, suffix) {
var chunk = ignoredCustomMarkupChunks[+index];
if (options.collapseWhitespace) {
if (prefix !== '\t') {
Expand Down
4 changes: 2 additions & 2 deletions dist/htmlminifier.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<body>
<div id="outer-wrapper">
<div id="wrapper">
<h1>HTML Minifier <span>(v2.1.6)</span></h1>
<h1>HTML Minifier <span>(v2.1.7)</span></h1>
<textarea rows="8" cols="40" id="input"></textarea>
<div class="minify-button">
<button type="button" id="minify-btn">Minify</button>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "html-minifier",
"description": "Highly configurable, well-tested, JavaScript-based HTML minifier.",
"version": "2.1.6",
"version": "2.1.7",
"keywords": [
"cli",
"compress",
Expand Down Expand Up @@ -66,7 +66,7 @@
"grunt": "1.0.x",
"grunt-browserify": "5.0.x",
"grunt-contrib-uglify": "1.0.x",
"grunt-eslint": "18.1.x",
"grunt-eslint": "19.0.x",
"phantomjs-prebuilt": "2.1.x",
"qunitjs": "2.x"
},
Expand Down

0 comments on commit 049ce62

Please sign in to comment.