html-minifier 3.5.19 → 3.5.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/package.json +4 -4
- package/src/htmlminifier.js +54 -38
package/README.md
CHANGED
|
@@ -20,19 +20,19 @@ How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Pe
|
|
|
20
20
|
|
|
21
21
|
| Site | Original size *(KB)* | HTMLMinifier | minimize | Will Peavy | htmlcompressor.com |
|
|
22
22
|
| ---------------------------------------------------------------------------- |:--------------------:| ------------:| --------:| ----------:| ------------------:|
|
|
23
|
-
| [Google](https://www.google.com/) |
|
|
24
|
-
| [Twitter](https://twitter.com/) |
|
|
25
|
-
| [HTMLMinifier](https://github.com/kangax/html-minifier) |
|
|
26
|
-
| [New York Times](https://www.nytimes.com/) |
|
|
27
|
-
| [Stack Overflow](https://stackoverflow.com/) |
|
|
23
|
+
| [Google](https://www.google.com/) | 47 | **43** | 47 | 49 | 47 |
|
|
24
|
+
| [Twitter](https://twitter.com/) | 146 | **115** | 138 | 155 | 138 |
|
|
25
|
+
| [HTMLMinifier](https://github.com/kangax/html-minifier) | 171 | **128** | 143 | 148 | 142 |
|
|
26
|
+
| [New York Times](https://www.nytimes.com/) | 207 | **139** | 158 | 155 | 144 |
|
|
27
|
+
| [Stack Overflow](https://stackoverflow.com/) | 256 | **199** | 209 | 217 | 206 |
|
|
28
28
|
| [Bootstrap CSS](https://getbootstrap.com/docs/3.3/css/) | 271 | **260** | 269 | 229 | 269 |
|
|
29
|
-
| [BBC](https://www.bbc.co.uk/) |
|
|
30
|
-
| [Amazon](https://www.amazon.co.uk/) |
|
|
31
|
-
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) |
|
|
32
|
-
| [NBC](https://www.nbc.com/) |
|
|
29
|
+
| [BBC](https://www.bbc.co.uk/) | 294 | **238** | 285 | 289 | 278 |
|
|
30
|
+
| [Amazon](https://www.amazon.co.uk/) | 377 | **328** | 368 | 379 | n/a |
|
|
31
|
+
| [Wikipedia](https://en.wikipedia.org/wiki/President_of_the_United_States) | 520 | **484** | 504 | 523 | 503 |
|
|
32
|
+
| [NBC](https://www.nbc.com/) | 669 | **633** | 668 | 669 | n/a |
|
|
33
33
|
| [Eloquent Javascript](https://eloquentjavascript.net/1st_edition/print.html) | 870 | **815** | 840 | 864 | n/a |
|
|
34
|
-
| [ES6 table](https://kangax.github.io/compat-table/es6/) |
|
|
35
|
-
| [ES6 draft](https://tc39.github.io/ecma262/) |
|
|
34
|
+
| [ES6 table](https://kangax.github.io/compat-table/es6/) | 5243 | **4472** | 4963 | n/a | n/a |
|
|
35
|
+
| [ES6 draft](https://tc39.github.io/ecma262/) | 6072 | **5449** | 5615 | n/a | n/a |
|
|
36
36
|
|
|
37
37
|
## Options Quick Reference
|
|
38
38
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "html-minifier",
|
|
3
3
|
"description": "Highly configurable, well-tested, JavaScript-based HTML minifier.",
|
|
4
|
-
"version": "3.5.
|
|
4
|
+
"version": "3.5.20",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
7
7
|
"compress",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"camel-case": "3.0.x",
|
|
58
|
-
"clean-css": "4.
|
|
59
|
-
"commander": "2.
|
|
58
|
+
"clean-css": "4.2.x",
|
|
59
|
+
"commander": "2.17.x",
|
|
60
60
|
"he": "1.1.x",
|
|
61
61
|
"param-case": "2.1.x",
|
|
62
62
|
"relateurl": "0.2.x",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"grunt": "1.0.x",
|
|
67
67
|
"grunt-browserify": "5.3.x",
|
|
68
|
-
"grunt-contrib-uglify": "3.
|
|
68
|
+
"grunt-contrib-uglify": "3.4.x",
|
|
69
69
|
"gruntify-eslint": "4.0.x",
|
|
70
70
|
"phantomjs-prebuilt": "2.1.x",
|
|
71
71
|
"qunit": "2.x"
|
package/src/htmlminifier.js
CHANGED
|
@@ -335,23 +335,33 @@ function isMetaViewport(tag, attrs) {
|
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
function wrapInlineCSS(text) {
|
|
341
|
-
return '*{' + text + '}';
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
function unwrapInlineCSS(text) {
|
|
345
|
-
var matches = text.match(/^\*\{([\s\S]*)\}$/);
|
|
346
|
-
return matches ? matches[1] : text;
|
|
338
|
+
function ignoreCSS(id) {
|
|
339
|
+
return '/* clean-css ignore:start */' + id + '/* clean-css ignore:end */';
|
|
347
340
|
}
|
|
348
341
|
|
|
349
|
-
|
|
350
|
-
|
|
342
|
+
// Wrap CSS declarations for CleanCSS > 3.x
|
|
343
|
+
// See https://github.com/jakubpawlowicz/clean-css/issues/418
|
|
344
|
+
function wrapCSS(text, type) {
|
|
345
|
+
switch (type) {
|
|
346
|
+
case 'inline':
|
|
347
|
+
return '*{' + text + '}';
|
|
348
|
+
case 'media':
|
|
349
|
+
return '@media ' + text + '{a{top:0}}';
|
|
350
|
+
default:
|
|
351
|
+
return text;
|
|
352
|
+
}
|
|
351
353
|
}
|
|
352
354
|
|
|
353
|
-
function
|
|
354
|
-
var matches
|
|
355
|
+
function unwrapCSS(text, type) {
|
|
356
|
+
var matches;
|
|
357
|
+
switch (type) {
|
|
358
|
+
case 'inline':
|
|
359
|
+
matches = text.match(/^\*\{([\s\S]*)\}$/);
|
|
360
|
+
break;
|
|
361
|
+
case 'media':
|
|
362
|
+
matches = text.match(/^@media ([\s\S]*?)\s*{[\s\S]*}$/);
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
355
365
|
return matches ? matches[1] : text;
|
|
356
366
|
}
|
|
357
367
|
|
|
@@ -655,20 +665,7 @@ function processOptions(values) {
|
|
|
655
665
|
return prefix + quote + options.minifyURLs(url) + quote + suffix;
|
|
656
666
|
});
|
|
657
667
|
try {
|
|
658
|
-
|
|
659
|
-
text = wrapInlineCSS(text);
|
|
660
|
-
}
|
|
661
|
-
else if (type === 'media') {
|
|
662
|
-
text = wrapMediaQuery(text);
|
|
663
|
-
}
|
|
664
|
-
text = new CleanCSS(value).minify(text).styles;
|
|
665
|
-
if (type === 'inline') {
|
|
666
|
-
text = unwrapInlineCSS(text);
|
|
667
|
-
}
|
|
668
|
-
else if (type === 'media') {
|
|
669
|
-
text = unwrapMediaQuery(text);
|
|
670
|
-
}
|
|
671
|
-
return text;
|
|
668
|
+
return unwrapCSS(new CleanCSS(value).minify(wrapCSS(text, type)).styles, type);
|
|
672
669
|
}
|
|
673
670
|
catch (err) {
|
|
674
671
|
options.log(err);
|
|
@@ -859,15 +856,6 @@ function minify(value, options, partialMarkup) {
|
|
|
859
856
|
return token;
|
|
860
857
|
});
|
|
861
858
|
|
|
862
|
-
function escapeFragments(fn) {
|
|
863
|
-
return function(text, type) {
|
|
864
|
-
return fn(text.replace(uidPattern, function(match, prefix, index) {
|
|
865
|
-
var chunks = ignoredCustomMarkupChunks[+index];
|
|
866
|
-
return chunks[1] + uidAttr + index + chunks[2];
|
|
867
|
-
}), type);
|
|
868
|
-
};
|
|
869
|
-
}
|
|
870
|
-
|
|
871
859
|
var customFragments = options.ignoreCustomFragments.map(function(re) {
|
|
872
860
|
return re.source;
|
|
873
861
|
});
|
|
@@ -879,10 +867,38 @@ function minify(value, options, partialMarkup) {
|
|
|
879
867
|
uidAttr = uniqueId(value);
|
|
880
868
|
uidPattern = new RegExp('(\\s*)' + uidAttr + '([0-9]+)(\\s*)', 'g');
|
|
881
869
|
if (options.minifyCSS) {
|
|
882
|
-
options.minifyCSS =
|
|
870
|
+
options.minifyCSS = (function(fn) {
|
|
871
|
+
return function(text, type) {
|
|
872
|
+
text = text.replace(uidPattern, function(match, prefix, index) {
|
|
873
|
+
var chunks = ignoredCustomMarkupChunks[+index];
|
|
874
|
+
return chunks[1] + uidAttr + index + chunks[2];
|
|
875
|
+
});
|
|
876
|
+
var ids = [];
|
|
877
|
+
new CleanCSS().minify(wrapCSS(text, type)).warnings.forEach(function(warning) {
|
|
878
|
+
var match = uidPattern.exec(warning);
|
|
879
|
+
if (match) {
|
|
880
|
+
var id = uidAttr + match[2];
|
|
881
|
+
text = text.replace(id, ignoreCSS(id));
|
|
882
|
+
ids.push(id);
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
text = fn(text, type);
|
|
886
|
+
ids.forEach(function(id) {
|
|
887
|
+
text = text.replace(ignoreCSS(id), id);
|
|
888
|
+
});
|
|
889
|
+
return text;
|
|
890
|
+
};
|
|
891
|
+
})(options.minifyCSS);
|
|
883
892
|
}
|
|
884
893
|
if (options.minifyJS) {
|
|
885
|
-
options.minifyJS =
|
|
894
|
+
options.minifyJS = (function(fn) {
|
|
895
|
+
return function(text, type) {
|
|
896
|
+
return fn(text.replace(uidPattern, function(match, prefix, index) {
|
|
897
|
+
var chunks = ignoredCustomMarkupChunks[+index];
|
|
898
|
+
return chunks[1] + uidAttr + index + chunks[2];
|
|
899
|
+
}), type);
|
|
900
|
+
};
|
|
901
|
+
})(options.minifyJS);
|
|
886
902
|
}
|
|
887
903
|
}
|
|
888
904
|
var token = uidAttr + ignoredCustomMarkupChunks.length;
|