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 fc9dc8c
Browse filesBrowse the repository at this point in the historyBrowse files
feat(html): minify the document an <iframe srcdoc> holds (#21767)
* feat(html): minify the document an <iframe srcdoc> holds
Adds `optimization.minimize.html.minifySrcdoc`, off by default. The body is a
whole document of its own, so like a conditional comment's it cannot be
minified where it is found: the values are recorded, minified, and put back
into the source, which is then minified as usual. A nested iframe recurses.
* fix(html): scope the srcdoc minifier and quote what it writes back
An `<iframe>` in foreign content is an SVG or MathML element sharing the
name, so its `srcdoc` is not this attribute and its value is left alone. A
value written without quotes gains them: a document holds spaces and `>`,
either of which would end a bare value and swallow the attribute after it.
* fix(html): minify a conditional comment inside a srcdoc too
The nested body went through a bare processor, so a downlevel-hidden
conditional comment in there kept its unminified markup when both options
were on. Both nested languages now go through one whole-document function,
which the srcdoc pass recurses into.
* fix(html): put a conditional comment's body back by offset
Rewriting it with `replace` found the body's first occurrence, which is
inside the condition when the condition reads the same — `<!--[if IE ]> IE`
had its condition minified and its body left alone. The offsets are recorded
instead of the text.
* fix(html): put a conditional comment back where it was parsed
Splicing it into the output rewrote every identical string there, so the same
markup written inside a script was minified as if it were the comment. The
body now goes back into the source by offset, the way a srcdoc's does, which
drops the recording pass with it.
Copy file name to clipboardExpand all lines: .changeset/048-html-remove-redundant-attributes.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,4 +2,4 @@
2
2
"webpack": minor
3
3
---
4
4
5
-
Minify HTML further: leave out the implied `<html>` tag and any optional end tag nothing prints behind, print an empty attribute value bare, write an attribute value in the fewest bytes that parse back the same, drop an empty attribute and a run of nested empty elements, fold an enumerated value to lower case, and add the `optimization.minimize.html` options `collapseWhitespace`, `mergeStyles`, `minifyConditionalComments`, `preserveComments`, `removeEmptyAttributes`, `removeEmptyElements`, `removeImpliedTags`, `removeRedundantAttributes`, `sortAttributes` and `sortTokenLists`.
5
+
Minify HTML further: leave out the implied `<html>` tag and any optional end tag nothing prints behind, print an empty attribute value bare, write an attribute value in the fewest bytes that parse back the same, drop an empty attribute and a run of nested empty elements, fold an enumerated value to lower case, and add the `optimization.minimize.html` options `collapseWhitespace`, `mergeStyles`, `minifyConditionalComments`, `minifySrcdoc` (minify the document an `<iframe srcdoc>` holds), `preserveComments`, `removeEmptyAttributes`, `removeEmptyElements`, `removeImpliedTags`, `removeRedundantAttributes`, `sortAttributes` and `sortTokenLists`.
* Minify the document held in an `<iframe srcdoc>` attribute. Off by default: the body is a whole document of its own (its base URL is `about:srcdoc`), so minifying it is safe, but the attribute is readable from script and a consumer comparing `iframe.srcdoc` byte for byte would see it change.
2450
+
* @since 5.110.0
2451
+
*/
2452
+
minifySrcdoc?: boolean;
2448
2453
/**
2449
2454
* Patterns naming comments to keep, on top of the ones minifying always keeps (downlevel conditional comments, server-side includes and template directives). A string is read as a regular expression source and matched against the comment's text.
Copy file name to clipboardExpand all lines: lib/html/htmlMinify.js
+90-44Lines changed: 90 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@
23
23
* re-resolves in the worker — via the installed package, or the dev self-link.
24
24
* @param {{ [file: string]: string }} input a single `{ filename: code }` entry
25
25
* @param {(RawSourceMap | undefined)=} sourceMap input source map (unused: safe serialize keeps positions token-coarse, so no map is produced yet)
26
-
* @param {HtmlPrintOptions & { minifyConditionalComments?: boolean }=} minimizerOptions minimizer options — `environment`, `convertLengthUnits` and `rewriteCustomProperties` reach the CSS minifier this runs over inline CSS; the rest is `optimization.minimize.html`
26
+
* @param {HtmlPrintOptions & { minifyConditionalComments?: boolean, minifySrcdoc?: boolean }=} minimizerOptions minimizer options — `environment`, `convertLengthUnits` and `rewriteCustomProperties` reach the CSS minifier this runs over inline CSS; the rest is `optimization.minimize.html`
Copy file name to clipboardExpand all lines: schemas/WebpackOptions.json
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3793,6 +3793,11 @@
3793
3793
"type": "boolean",
3794
3794
"added": "5.110.0"
3795
3795
},
3796
+
"minifySrcdoc": {
3797
+
"description": "Minify the document held in an `<iframe srcdoc>` attribute. Off by default: the body is a whole document of its own (its base URL is `about:srcdoc`), so minifying it is safe, but the attribute is readable from script and a consumer comparing `iframe.srcdoc` byte for byte would see it change.",
3798
+
"type": "boolean",
3799
+
"added": "5.110.0"
3800
+
},
3796
3801
"preserveComments": {
3797
3802
"description": "Patterns naming comments to keep, on top of the ones minifying always keeps (downlevel conditional comments, server-side includes and template directives). A string is read as a regular expression source and matched against the comment's text.",
"description": "Minify the document held in an \`<iframe srcdoc>\` attribute. Off by default: the body is a whole document of its own (its base URL is \`about:srcdoc\`), so minifying it is safe, but the attribute is readable from script and a consumer comparing \`iframe.srcdoc\` byte for byte would see it change.",
"description": "Minify the document held in an \`<iframe srcdoc>\` attribute. Off by default: the body is a whole document of its own (its base URL is \`about:srcdoc\`), so minifying it is safe, but the attribute is readable from script and a consumer comparing \`iframe.srcdoc\` byte for byte would see it change.",
0 commit comments