You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ea21f56
Browse filesBrowse the repository at this point in the historyBrowse files
feat(html): add normalizeUrlAttributes and widen two attribute rewrites (#21960)
* feat(html): add `normalizeUrlAttributes` and widen two attribute rewrites
Minifying trimmed the whitespace around a URL with nothing able to stop it,
though it keeps what the DOM parses and changes the string `getAttribute`
hands back like every rewrite that already has a switch. `normalizeUrlAttributes`
names it, on by default.
`collapseBooleanAttributes` gains the `"all"` tier its own TODO asked for:
`true` still rewrites only the spelling the spec canonicalizes, `"all"` any
value, including the `checked="false"` that already means checked.
`sortTokenLists` now sorts whatever `normalizeListAttributes` says, which is
what its description already claimed — putting tokens in another order
rewrites the separators between them anyway.
A `style` attribute needs no switch of its own: it is an embedded body, so a
renderer answering with the list it was given keeps it. That worked only
synchronously — where the answer is deferred, an answer nothing beats was
read as no answer and the built-in's text stood, which is the path webpack's
own minimizer takes. It now leaves the attribute as written, delimiter and
all, the way a deferred `srcdoc` already did.
Co-authored-by: aryanraj45 <[email protected]>
* fix(html): offer a deferred `style` list already at its shortest
A list the built-in leaves as it found it — `margin:0 auto`, which cannot go
unquoted either — is one `_writeAttribute` declines, and the attribute then
took the source path without deferring, so no renderer was ever asked about
it. The synchronous path asks whatever the built-in made of it, and now this
one does too, with the source standing until an answer arrives.
Co-authored-by: aryanraj45 <[email protected]>
* docs(html): say what `normalizeUrlAttributes` changes for a reader
`getAttribute` hands back the content attribute as written, so trimming one
is a value a script comparing those bytes reads differently — which is the
reason the switch exists. The description read as though the trim were the
attribute's own doing, which is true of resolving the URL and of nothing
else.
Co-authored-by: aryanraj45 <[email protected]>
---------
Co-authored-by: aryanraj45 <[email protected]>
* Write a boolean attribute spelled with its own name (`disabled="disabled"`) as the bare name the spec canonicalizes it to. On by default.
2559
+
* Write a boolean attribute as the bare name its presence already means. The DOM reads `checked` from the attribute being there and never from its value, so `checked="checked"` and `checked=""` are the same element — but `getAttribute` hands back what was written. `true`, the default, rewrites only the spelling the spec itself canonicalizes, the attribute's own name; `"all"` rewrites any value, including the `checked="false"` that already means checked.
2560
2560
* @since 5.110.0
2561
2561
*/
2562
-
collapseBooleanAttributes?: boolean;
2562
+
collapseBooleanAttributes?: "all" |boolean;
2563
2563
/**
2564
2564
* Collapse each run of whitespace in text to a single space. Left alone inside `pre`, `textarea` and `listing`, where whitespace renders verbatim. `true` (or `"conservative"`) never removes whitespace entirely — dropping it would join two inline elements that render apart. `"smart"` also drops the whitespace that sits against a block element's edge, where no line box reaches it. `"all"` drops the whitespace at every text node's edges, which does change how adjacent inline elements render.
* Drop the ASCII whitespace around a URL value (`href`, `src`, `action`, `poster`, …), which resolving the URL skips over, so the request goes to the same place either way. On by default: `getAttribute` hands back the attribute as written, so a script comparing those bytes is the one this is turned off for.
2610
+
* @since 5.111.0
2611
+
*/
2612
+
normalizeUrlAttributes?: boolean;
2608
2613
/**
2609
2614
* Drop an attribute whose empty or all-whitespace value leaves it in the state its absence gives: the globals `class`, `id`, `style`, `dir`, `accesskey`, `itemprop`, `itemref`, `itemtype` and `part`, and every attribute reflecting a token list on the elements the spec defines it for — `rel` on `<a>`, `<area>`, `<form>` and `<link>`, `ping` on `<a>` and `<area>`, `headers` on `<td>` and `<th>`, `blocking` on `<link>`, `<script>` and `<style>`, `sizes` on `<link>`, `for` on `<output>` — where an empty list is no tokens. Anywhere else that spelling is an author attribute whose meaning is a script's, so `<x-foo rel="">` and `<label for="">` keep it. Off by default: an attribute selector matches on presence, so `[class]` stops matching. Never dropped: `title` and `lang`, whose empty value means what absence does not; `sandbox`, whose empty list is the most restrictive state an `<iframe>` has; and an event handler, whose empty body still compiles to a function where absence reads null.
* Print every space-separated token list the DOM reads as a set — `class`, `rel`, `part`, `sandbox`, `blocking`, `itemprop` / `itemref` / `itemtype`, `<output for>` and `<link sizes>` — in token order. Nothing matching those reads order, so this only makes the same markup compress better across pages. Off by default: a script reading `className` or `rel` back sees the new order. The lists the DOM does not read as a set are left alone whatever this says — `ping` is the order its requests go out in and `accesskey` the order its keys are tried.
2644
+
* Print every space-separated token list the DOM reads as a set — `class`, `rel`, `part`, `sandbox`, `blocking`, `itemprop` / `itemref` / `itemtype`, `<output for>` and `<link sizes>` — in token order. Nothing matching those reads order, so this only makes the same markup compress better across pages. Off by default: a script reading `className` or `rel` back sees the new order. Asked for on its own: a list this reorders is rewritten whether or not `normalizeListAttributes` is on, since another order is another spelling. The lists the DOM does not read as a set are left alone whatever this says — `ping` is the order its requests go out in and `accesskey` the order its keys are tried.
* What the minifying printer may rewrite. Every entry is on unless it is
8915
8915
* `false`, so a document one transform breaks can still be minified by the rest.
8916
8916
* @typedef {object} HtmlTransformOptions
8917
-
* @property {boolean=} collapseBooleanAttributes write a boolean attribute spelled with its own name (`disabled="disabled"`) as the bare name
8917
+
* @property {(boolean | "all")=} collapseBooleanAttributes write a boolean attribute as the bare name its presence already means; `true` only the spellings the spec canonicalizes, `"all"` any value
8918
8918
* @property {(boolean | "all" | "some" | string | RegExp | ((comment: string) => boolean))=} comments which comments survive: `"some"` (the default) the ones that carry something, `true` / `"all"` every one, `false` none, or the ones a pattern matches / a predicate accepts, over the comment's own text. A comment a parser or a server reads is kept whatever this says
8919
8919
* @property {boolean=} normalizeAttributeQuotes drop or re-pick an attribute value's quotes
8920
8920
* @property {boolean=} normalizeEnumeratedAttributes fold an enumerated value to the keyword it names
8921
8921
* @property {boolean=} normalizeListAttributes normalize a space-, comma- or descriptor-separated list value (`class`, `rel`, `srcset`, `sizes`, the viewport `content`)
8922
8922
* @property {boolean=} normalizeNumericAttributes write an integer attribute the one way its rules read it
8923
+
* @property {boolean=} normalizeUrlAttributes drop the whitespace around a URL value (`href`, `src`, `action`, …), which resolving the URL skips over
8923
8924
* @property {boolean=} removeOptionalTags leave out an optional tag other than the `<html>` / `<head>` / `<body>` shell, which is `removeImpliedTags`
Copy file name to clipboardExpand all lines: schemas/WebpackOptions.json
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -3903,8 +3903,15 @@
3903
3903
"additionalProperties": false,
3904
3904
"properties": {
3905
3905
"collapseBooleanAttributes": {
3906
-
"description": "Write a boolean attribute spelled with its own name (`disabled=\"disabled\"`) as the bare name the spec canonicalizes it to. On by default.",
3907
-
"type": "boolean",
3906
+
"description": "Write a boolean attribute as the bare name its presence already means. The DOM reads `checked` from the attribute being there and never from its value, so `checked=\"checked\"` and `checked=\"\"` are the same element — but `getAttribute` hands back what was written. `true`, the default, rewrites only the spelling the spec itself canonicalizes, the attribute's own name; `\"all\"` rewrites any value, including the `checked=\"false\"` that already means checked.",
3907
+
"anyOf": [
3908
+
{
3909
+
"enum": ["all"]
3910
+
},
3911
+
{
3912
+
"type": "boolean"
3913
+
}
3914
+
],
3908
3915
"added": "5.110.0"
3909
3916
},
3910
3917
"collapseWhitespace": {
@@ -3972,6 +3979,11 @@
3972
3979
"type": "boolean",
3973
3980
"added": "5.110.0"
3974
3981
},
3982
+
"normalizeUrlAttributes": {
3983
+
"description": "Drop the ASCII whitespace around a URL value (`href`, `src`, `action`, `poster`, …), which resolving the URL skips over, so the request goes to the same place either way. On by default: `getAttribute` hands back the attribute as written, so a script comparing those bytes is the one this is turned off for.",
3984
+
"type": "boolean",
3985
+
"added": "5.111.0"
3986
+
},
3975
3987
"removeEmptyAttributes": {
3976
3988
"description": "Drop an attribute whose empty or all-whitespace value leaves it in the state its absence gives: the globals `class`, `id`, `style`, `dir`, `accesskey`, `itemprop`, `itemref`, `itemtype` and `part`, and every attribute reflecting a token list on the elements the spec defines it for — `rel` on `<a>`, `<area>`, `<form>` and `<link>`, `ping` on `<a>` and `<area>`, `headers` on `<td>` and `<th>`, `blocking` on `<link>`, `<script>` and `<style>`, `sizes` on `<link>`, `for` on `<output>` — where an empty list is no tokens. Anywhere else that spelling is an author attribute whose meaning is a script's, so `<x-foo rel=\"\">` and `<label for=\"\">` keep it. Off by default: an attribute selector matches on presence, so `[class]` stops matching. Never dropped: `title` and `lang`, whose empty value means what absence does not; `sandbox`, whose empty list is the most restrictive state an `<iframe>` has; and an event handler, whose empty body still compiles to a function where absence reads null.",
3977
3989
"type": "boolean",
@@ -4017,7 +4029,7 @@
4017
4029
"added": "5.110.0"
4018
4030
},
4019
4031
"sortTokenLists": {
4020
-
"description": "Print every space-separated token list the DOM reads as a set — `class`, `rel`, `part`, `sandbox`, `blocking`, `itemprop` / `itemref` / `itemtype`, `<output for>` and `<link sizes>` — in token order. Nothing matching those reads order, so this only makes the same markup compress better across pages. Off by default: a script reading `className` or `rel` back sees the new order. The lists the DOM does not read as a set are left alone whatever this says — `ping` is the order its requests go out in and `accesskey` the order its keys are tried.",
4032
+
"description": "Print every space-separated token list the DOM reads as a set — `class`, `rel`, `part`, `sandbox`, `blocking`, `itemprop` / `itemref` / `itemtype`, `<output for>` and `<link sizes>` — in token order. Nothing matching those reads order, so this only makes the same markup compress better across pages. Off by default: a script reading `className` or `rel` back sees the new order. Asked for on its own: a list this reorders is rewritten whether or not `normalizeListAttributes` is on, since another order is another spelling. The lists the DOM does not read as a set are left alone whatever this says — `ping` is the order its requests go out in and `accesskey` the order its keys are tried.",
0 commit comments