feat(html/minifier): Compress characters in head (#4682)

This commit is contained in:
Alexander Akait 2022-05-19 04:15:40 +03:00 committed by GitHub
parent b509ca0c7b
commit cac8cee62a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 180 additions and 180 deletions

View File

@ -340,7 +340,13 @@ impl VisitMut for Minifier {
self.current_element_namespace = old_current_element_namespace;
self.is_script_json_ld = old_value_is_script_json_ld;
n.children.retain(|child| !matches!(child, Child::Comment(comment) if !self.is_conditional_comment(&comment.data)));
let allow_to_remove_spaces = &*n.tag_name == "head" && n.namespace == Namespace::HTML;
n.children.retain(|child| match child {
Child::Comment(comment) if !self.is_conditional_comment(&comment.data) => false,
Child::Text(_) if allow_to_remove_spaces => false,
_ => true,
});
let mut already_seen: AHashSet<JsWord> = Default::default();

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<a href=13.html id=rm13 aria-labelledby="rm13 attr">read more</a>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<p><button autofocus value=next>Button</button></p>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<p class="foo bar">foo bar baz</p>
<p class=foo>foo bar baz</p>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<table width=200 border=1 align=center cellpadding=4 cellspacing=0>
<tbody><tr>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<div contenteditable="">Stress reliever</div>
<div contenteditable="">Stress reliever</div>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<input class=form-control id={{vm.formInputName}} name={{vm.formInputName}} placeholder=YYYY-MM-DD date-range-picker data-ng-model=vm.value data-ng-model-options="{ debounce: 1000 }" data-ng-pattern=vm.options.format data-options=vm.datepickerOptions>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<p title=\n lang="" dir="">x</p>
<p>x</p>

View File

@ -1,7 +1,4 @@
<!doctype html><html><head>
<meta charset=utf-8>
<title>Test</title>
</head>
<!doctype html><html><head><meta charset=utf-8><title>Test</title></head>
<body>
<form action=handler.php method=post>
<input name=str>

View File

@ -1,9 +1,4 @@
<!doctype html><html lang=en><head>
<meta charset=UTF-8>
<meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv=X-UA-Compatible content="ie=edge">
<title>Document</title>
</head>
<!doctype html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title></head>
<body>
<iframe id=test src=test.html></iframe>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<img src=test.png alt=test>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<input name=a>
<input name=b>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<form action=/test>
<input onkeydown=myFunction()>

View File

@ -1,12 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
<link rel=stylesheet href=a.css>
<link rel=stylesheet href=b.css>
<link rel=stylesheet href=b.css>
<link rel=stylesheet href=c.css>
<link rel=stylesheet href=d.css type="">
<link rel=stylesheet href=d.css type=unknown/unknown>
</head>
<!doctype html><html lang=en><head><title>Document</title><link rel=stylesheet href=a.css><link rel=stylesheet href=b.css><link rel=stylesheet href=b.css><link rel=stylesheet href=c.css><link rel=stylesheet href=d.css type=""><link rel=stylesheet href=d.css type=unknown/unknown></head>
<body>
<div>test</div>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<meter id=fuel max=100 low=33 high=66 optimum=80 value=50>
at 50/100

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<ol>
<li>Mix flour, baking powder, sugar, and salt.</li>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<progress></progress>

View File

@ -1,9 +1,4 @@
<!doctype html><html lang=en><head>
<meta charset=UTF-8>
<meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv=X-UA-Compatible content="ie=edge">
<title>Document</title>
</head>
<!doctype html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title></head>
<body>
<div data-test=test></div>
<div data-test=test></div>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<a href=# rel="value1 nofollow">Link</a>
<a href=# rel="value1 nofollow">Link</a>

View File

@ -1,14 +1,10 @@
<!doctype html><html><head><script defer>
console.log();
</script>
<script>
</script><script>
console.log();
</script>
<script type=module>
</script><script type=module>
console.log();
</script>
<script>window.jQuery || document.write('<script src="jquery.js"><\/script>')</script>
<script type=text/html>
</script><script>window.jQuery || document.write('<script src="jquery.js"><\/script>')</script><script type=text/html>
<div>
test
</div>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<p title=bar>foo</p>
<p title=bar>foo</p>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<img srcset="elva-fairy-480w.jpg 480w,elva-fairy-800w.jpg 800w" sizes="(max-width: 600px) 480px,800px" src=elva-fairy-800w.jpg alt="Elva dressed as a fairy">

View File

@ -1,30 +1,22 @@
<!doctype html><html lang=en><head>
<title>Document</title>
<style>
<!doctype html><html lang=en><head><title>Document</title><style>
h1 {color:red;}
p {color:blue;}
</style>
<style>
</style><style>
h1 {color:red;}
p {color:blue;}
</style>
<style>
</style><style>
h1 {color:red;}
p {color:blue;}
</style>
<style type=" ">
</style><style type=" ">
h1 {color:red;}
p {color:blue;}
</style>
<style>
</style><style>
h1 {color:red;}
p {color:blue;}
</style>
<style type=unknown/unknown>
</style><style type=unknown/unknown>
h1 {color:red;}
p {color:blue;}
</style>
</head>
</style></head>
<body>
<p style="color: red; background-color: rgb(100, 75, 200);"></p>
<p></p>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<textarea name=test id=test></textarea>

View File

@ -1,9 +1,4 @@
<!doctype html><html lang=en><head>
<meta charset=UTF-8>
<meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv=X-UA-Compatible content="ie=edge">
<title>Document</title>
</head>
<!doctype html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title></head>
<body>
<video controls src=/media/cc0-videos/friday.mp4>

View File

@ -1,21 +1,10 @@
<!doctype html><html lang=en><head>
<meta charset=UTF-8>
<meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv=X-UA-Compatible content="ie=edge">
<title>Document</title>
<!--[if !IE]>-->
<link href=non-ie.css rel=stylesheet>
<!--<![endif]-->
<!--[if IE]>
<!doctype html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title><!--[if !IE]>--><link href=non-ie.css rel=stylesheet><!--<![endif]--><!--[if IE]>
<link type="text/css" rel="stylesheet" href="/stylesheets/no-ie.css">
<![endif]-->
<!--[if IE 8]>
<![endif]--><!--[if IE 8]>
<link href="ie8only.css" rel="stylesheet">
<![endif]-->
<!-- [if IE 8]>
<![endif]--><!-- [if IE 8]>
<link href="ie8only.css" rel="stylesheet">
<![endif] -->
</head>
<![endif] --></head>
<body>

View File

@ -1,7 +1,4 @@
<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head>
<title>!DOCTYPE</title>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
</head>
<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>!DOCTYPE</title><meta http-equiv=Content-Type content="text/html; charset=utf-8"></head>
<body>
<p>Test</p>

View File

@ -1,6 +1,4 @@
<!doctype html><html><head>
<title>Title of the document</title>
</head>
<!doctype html><html><head><title>Title of the document</title></head>
<body>
The content of the document......

View File

@ -1,6 +1,4 @@
<!doctype html><html><head>
<title>Title of the document</title>
</head>
<!doctype html><html><head><title>Title of the document</title></head>
<body>
The content of the document......

View File

@ -1,6 +1,4 @@
<!doctype html system "about:legacy-compat"><html lang=en><head>
<title>Document</title>
</head>
<!doctype html system "about:legacy-compat"><html lang=en><head><title>Document</title></head>
<body>
<div>test</div>

View File

@ -1,9 +1,4 @@
<!doctype html><html lang=EN><head>
<meta charset=UTF-8>
<meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv=X-UA-Compatible content="ie=edge">
<title>Document</title>
</head>
<!doctype html><html lang=EN><head><meta charset=UTF-8><meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title></head>
<body>
<div data-test=Test>TEST</div>
<p>blah<span>blah 2<span>blah 3</span></span></p>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<a href=test.html><div>hey</div></a>
<a href>ok</a>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
test<br>test
test<br>test

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<begriffs.pagination ng-init="perPage=20" collection=logs url="\'/api/logs?user=-1\'" per-page=perPage per-page-presets=[10,20,50,100] template-url=/assets/paginate-anything.html></begriffs.pagination>
<some-tag-1></some-tag-1><some-tag-2></some-tag-2>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<form action="" class=form-example>
<div class=form-example>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<p>For more information, read <a href=https://stackoverflow.com/questions/17408815/fieldset-resizes-wrong-appears-to-have-unremovable-min-width-min-content/17863685#17863685>this Stack Overflow answer</a>.</p>
<p>a</p><div>b</div>

View File

@ -1,12 +1,7 @@
<!doctype html><html><head>
<title>Party Coffee Cake</title>
<script type=application/ld+json>{"@context":"https://schema.org/","@type":"Recipe","author":{"@type":"Person","name":"Mary Stone"},"datePublished":"2018-03-10","description":"This coffee cake is awesome and perfect for parties.","name":"Party Coffee Cake","prepTime":"PT20M"}</script>
<script type=application/ld+json crossorigin=anonymous>{"@context":"https://schema.org/","@type":"Recipe","author":{"@type":"Person","name":"Mary Stone"},"datePublished":"2018-03-10","description":"This coffee cake is awesome and perfect for parties.","name":"Party Coffee Cake","prepTime":"PT20M"}</script>
<script type=application/ld+json crossorigin=anonymous>
<!doctype html><html><head><title>Party Coffee Cake</title><script type=application/ld+json>{"@context":"https://schema.org/","@type":"Recipe","author":{"@type":"Person","name":"Mary Stone"},"datePublished":"2018-03-10","description":"This coffee cake is awesome and perfect for parties.","name":"Party Coffee Cake","prepTime":"PT20M"}</script><script type=application/ld+json crossorigin=anonymous>{"@context":"https://schema.org/","@type":"Recipe","author":{"@type":"Person","name":"Mary Stone"},"datePublished":"2018-03-10","description":"This coffee cake is awesome and perfect for parties.","name":"Party Coffee Cake","prepTime":"PT20M"}</script><script type=application/ld+json crossorigin=anonymous>
{
broken
</script>
<script type=unknown>
</script><script type=unknown>
{
"@context": "https://schema.org/",
"@type": "Recipe",
@ -19,10 +14,7 @@
"description": "This coffee cake is awesome and perfect for parties.",
"prepTime": "PT20M"
}
</script>
<script type=speculationrules>{"prerender":[{"score":0.5,"source":"list","urls":["/page/2"]},{"if_href_matches":["https://*.wikipedia.org/**"],"if_not_selector_matches":[".restricted-section *"],"score":0.1,"source":"document"}]}</script>
<script type=importmap>{"imports":{"lodash":"/node_modules/lodash-es/lodash.js","moment":"/node_modules/moment/src/moment.js"}}</script>
</head>
</script><script type=speculationrules>{"prerender":[{"score":0.5,"source":"list","urls":["/page/2"]},{"if_href_matches":["https://*.wikipedia.org/**"],"if_not_selector_matches":[".restricted-section *"],"score":0.1,"source":"document"}]}</script><script type=importmap>{"imports":{"lodash":"/node_modules/lodash-es/lodash.js","moment":"/node_modules/moment/src/moment.js"}}</script></head>
<body>
<h2>Party coffee cake recipe</h2>
<p>

View File

@ -1,9 +1,4 @@
<!doctype html><html lang=en><head>
<meta charset=UTF-8>
<meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv=X-UA-Compatible content="ie=edge">
<title>Document</title>
</head>
<!doctype html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title></head>
<body>
<template id=productrow>
<div class=foo>

View File

@ -1,6 +1,4 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<!doctype html><html lang=en><head><title>Document</title></head>
<body>
<div id='John"&Harry'>Test</div>

View File

@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<noscript>
<!-- anchor linking to external file -->
<a href="https://www.mozilla.com/">External Link</a>
</noscript>
<p>Rocks!</p>
</body>
</html>

View File

@ -0,0 +1,9 @@
<!doctype html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title></head>
<body>
<noscript>
<a href=https://www.mozilla.com/>External Link</a>
</noscript>
<p>Rocks!</p>
</body></html>

View File

@ -0,0 +1,21 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<template>
<div>
test
</div>
<ul>
<li>test</li>
<li>test</li>
</ul>
</template>
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,12 @@
<!doctype html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title><template>
<div>
test
</div>
<ul>
<li>test</li>
<li>test</li>
</ul>
</template></head>
<body>
</body></html>

View File

@ -0,0 +1,25 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>
Document
</title>
</head>
<body>
<p>
test
</p>
<ul>
<li>test1</li>
<li>test2</li>
<li>test3</li>
</ul>
</body>
</html>

View File

@ -0,0 +1,17 @@
<!doctype html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>
Document
</title></head>
<body>
<p>
test
</p>
<ul>
<li>test1</li>
<li>test2</li>
<li>test3</li>
</ul>
</body></html>

View File

@ -1,9 +1,4 @@
<!doctype html><html lang=en><head>
<meta charset=UTF-8>
<meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv=X-UA-Compatible content="ie=edge">
<title>Document</title>
</head>
<!doctype html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title></head>
<body>
<div data-test=one></div>

View File

@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
Test
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,6 @@
<!doctype html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title></head><body>Test
</body></html>