Skip to content

Commit 0021661

Browse files
domfarolinomfreed7
authored andcommitted
Add <iframe> lazyloading
Fixes whatwg#5496.
1 parent 5e19616 commit 0021661

File tree

1 file changed

+113
-30
lines changed

1 file changed

+113
-30
lines changed

source

Lines changed: 113 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6866,13 +6866,14 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
68666866
<li><p>Return false.</p></li>
68676867
</ol>
68686868

6869-
<p>Each <code>img</code> element has associated <dfn>lazy load resumption steps</dfn>, initially
6870-
null.</p>
6869+
<p>Each <code>img</code> and <code>iframe</code> element has associated <dfn>lazy load resumption
6870+
steps</dfn>, initially null.</p>
68716871

6872-
<p class="note">For <code>img</code> elements that <span data-x="will lazy load element
6873-
steps">will lazy load</span>, this can be set to true in the <span>lazy load intersection
6874-
observer</span>'s callback, which causes the image to load by continuing the <span>update the
6875-
image data</span> steps.</p>
6872+
<p class="note">For <code>img</code> and <code>iframe</code> elements that <span data-x="will lazy
6873+
load element steps">will lazy load</span>, these steps are run from the <span>lazy load
6874+
intersection observer</span>'s callback or when their <span>lazy loading attribute</span> is set
6875+
to the <span data-x="attr-loading-eager-state">Eager</span> state. This causes the element to
6876+
continue loading.</p>
68766877

68776878
<p>Each <code>Document</code> has a <dfn>lazy load intersection observer</dfn>, initially set to
68786879
null but can be set to an <code>IntersectionObserver</code> instance.</p>
@@ -26117,8 +26118,9 @@ interface <dfn>HTMLImageElement</dfn> : <span>HTMLElement</span> {
2611726118
loading attribute</span>. Its purpose is to indicate the policy for loading images that are
2611826119
outside the viewport.</p>
2611926120

26120-
<p>When the <code data-x="attr-img-loading">loading</code> attribute is set to the <span
26121-
data-x="attr-loading-eager-state">Eager</span> state, the user agent must run these steps:</p>
26121+
<p>When the <code data-x="attr-img-loading">loading</code> attribute's state is changed to the
26122+
<span data-x="attr-loading-eager-state">Eager</span> state, the user agent must run these
26123+
steps:</p>
2612226124

2612326125
<ol>
2612426126
<li><p>Let <var>resumptionSteps</var> be the <code>img</code> element's <span>lazy load
@@ -27919,7 +27921,7 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</code
2791927921

2792027922
<ol>
2792127923
<li><p>Set the <code>img</code>'s <span>lazy load resumption steps</span> to the rest of this
27922-
algorithm.</p></li>
27924+
algorithm starting with the step labeled <i>fetch the image</i>.</p></li>
2792327925

2792427926
<li><p><span>Start intersection-observing a lazy loading element</span> for the
2792527927
<code>img</code> element.</p></li>
@@ -27930,8 +27932,9 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</code
2793027932

2793127933
<li>
2793227934
<!--FETCH-->
27933-
<p><span data-x="concept-fetch">Fetch</span> <var>request</var>. Let this instance of the <span
27934-
data-x="concept-fetch">fetching</span> algorithm be associated with <var>image request</var>.
27935+
<p><i>Fetch the image</i>: <span data-x="concept-fetch">Fetch</span> <var>request</var>. Let
27936+
this instance of the <span data-x="concept-fetch">fetching</span> algorithm be associated with
27937+
<var>image request</var>.
2793527938
<!-- TODO "Interaction with the Preload Scanner" from the picture spec --></p>
2793627939

2793727940
<p>The resource obtained in this fashion, if any, is <var>image request</var>'s <span
@@ -29706,6 +29709,7 @@ href="?audio">audio&lt;/a> test instead.)&lt;/p></code></pre>
2970629709
<dd><code data-x="attr-dim-width">width</code></dd>
2970729710
<dd><code data-x="attr-dim-height">height</code></dd>
2970829711
<dd><code data-x="attr-iframe-referrerpolicy">referrerpolicy</code></dd>
29712+
<dd><code data-x="attr-iframe-loading">loading</code></dd>
2970929713
<dt><span
2971029714
data-x="concept-element-accessibility-considerations">Accessibility considerations</span>:</dt>
2971129715
<dd><a href="https://w3c.github.io/html-aria/#el-iframe">For authors</a>.</dd>
@@ -29726,6 +29730,7 @@ interface <dfn>HTMLIFrameElement</dfn> : <span>HTMLElement</span> {
2972629730
[<span>CEReactions</span>] attribute DOMString <span data-x="dom-dim-width">width</span>;
2972729731
[<span>CEReactions</span>] attribute DOMString <span data-x="dom-dim-height">height</span>;
2972829732
[<span>CEReactions</span>] attribute DOMString <span data-x="dom-iframe-referrerPolicy">referrerPolicy</span>;
29733+
[<span>CEReactions</span>] attribute DOMString <span data-x="dom-iframe-loading">loading</span>;
2972929734
readonly attribute <span>Document</span>? <span data-x="dom-iframe-contentDocument">contentDocument</span>;
2973029735
readonly attribute <span>WindowProxy</span>? <span data-x="dom-iframe-contentWindow">contentWindow</span>;
2973129736
<span>Document</span>? <span data-x="dom-media-getSVGDocument">getSVGDocument</span>();
@@ -29892,21 +29897,48 @@ interface <dfn>HTMLIFrameElement</dfn> : <span>HTMLElement</span> {
2989229897
<dt>If the <code data-x="attr-iframe-srcdoc">srcdoc</code> attribute is specified</dt>
2989329898

2989429899
<dd>
29895-
<p><span>Navigate</span><!--DONAV iframe--> the element's <span>nested browsing context</span>
29896-
to a new <span data-x="concept-response">response</span> whose <span
29897-
data-x="concept-response-url-list">url list</span> consists of <code>about:srcdoc</code>, <span
29898-
data-x="concept-response-header-list">header list</span> consists of `<code
29899-
data-x="">Content-Type</code>`/`<code>text/html</code>`, <span
29900-
data-x="concept-response-body">body</span> is the value of the attribute, <span
29901-
data-x="concept-response-csp-list">CSP list</span> is a <span data-x="list clone">clone</span>
29902-
of the <code>iframe</code> element's <span>node document</span>'s <span
29903-
data-x="concept-document-csp-list">CSP list</span>, <span
29904-
data-x="concept-response-https-state">HTTPS state</span> is the <span
29905-
data-x="concept-document-https-state">HTTPS state</span> of the <code>iframe</code> element's
29906-
<span>node document</span>.
29900+
<ol>
29901+
<li><p>Set the <code>iframe</code>'s <span>current navigation was lazy loaded</span> boolean
29902+
to false.</p></li>
29903+
29904+
<li>
29905+
<p>If the <span>will lazy load element steps</span> given the <code>iframe</code> element
29906+
return true, then:</p>
2990729907

29908-
<p>The resulting <code>Document</code> must be considered <span>an <code>iframe</code> <code
29909-
data-x="attr-iframe-srcdoc">srcdoc</code> document</span>.</p>
29908+
<ol>
29909+
<li><p>Set the <code>iframe</code>'s <span>lazy load resumption steps</span> to the rest of
29910+
this algorithm starting with the step labeled
29911+
<i>navigate to the srcdoc resource</i>.</p></li>
29912+
29913+
<li><p>Set the <code>iframe</code>'s <span>current navigation was lazy loaded</span> boolean
29914+
to true.</p></li>
29915+
29916+
<li><p><span>Start intersection-observing a lazy loading element</span> for the
29917+
<code>iframe</code> element.</p></li>
29918+
29919+
<li><p>Return.</p></li>
29920+
</ol>
29921+
</li>
29922+
29923+
<li>
29924+
<p><i>Navigate to the srcdoc resource</i>: <span>Navigate</span><!--DONAV iframe--> the
29925+
element's <span>nested browsing context</span> to a new <span
29926+
data-x="concept-response">response</span> whose <span data-x="concept-response-url-list">url
29927+
list</span> consists of <code>about:srcdoc</code>, <span
29928+
data-x="concept-response-header-list">header list</span> consists of `<code
29929+
data-x="">Content-Type</code>`/`<code>text/html</code>`, <span
29930+
data-x="concept-response-body">body</span> is the value of the attribute, <span
29931+
data-x="concept-response-csp-list">CSP list</span> is a <span data-x="list clone">clone</span>
29932+
of the <code>iframe</code> element's <span>node document</span>'s <span
29933+
data-x="concept-document-csp-list">CSP list</span>, <span
29934+
data-x="concept-response-https-state">HTTPS state</span> is the <span
29935+
data-x="concept-document-https-state">HTTPS state</span> of the <code>iframe</code> element's
29936+
<span>node document</span>.
29937+
29938+
<p>The resulting <code>Document</code> must be considered <span>an <code>iframe</code> <code
29939+
data-x="attr-iframe-srcdoc">srcdoc</code> document</span>.</p>
29940+
</li>
29941+
</ol>
2991029942
</dd>
2991129943

2991229944
<dt>Otherwise, if the element has no <code data-x="attr-iframe-src">src</code> attribute
@@ -29956,8 +29988,29 @@ interface <dfn>HTMLIFrameElement</dfn> : <span>HTMLElement</span> {
2995629988
element's <code data-x="attr-iframe-referrerpolicy">referrerpolicy</code> content
2995729989
attribute.</p></li>
2995829990

29959-
<li><p><span>Navigate</span><!--DONAV iframe--> the element's <span>nested browsing
29960-
context</span> to <var>resource</var>.</p></li>
29991+
<li><p>Set the <code>iframe</code>'s <span>current navigation was lazy loaded</span> boolean to
29992+
false.</p></li>
29993+
29994+
<li>
29995+
<p>If the element is an <code>iframe</code> element, and the <span>will lazy load element
29996+
steps</span> given the element return true, then:</p>
29997+
29998+
<ol>
29999+
<li><p>Set the <code>iframe</code>'s <span>lazy load resumption steps</span> to the rest of
30000+
this algorithm starting with the step labeled <i>navigate to the resource</i>.</p></li>
30001+
30002+
<li><p>Set the <code>iframe</code>'s <span>current navigation was lazy loaded</span> boolean
30003+
to true.</p></li>
30004+
30005+
<li><p><span>Start intersection-observing a lazy loading element</span> for the
30006+
<code>iframe</code> element.</p></li>
30007+
30008+
<li><p>Return.</p></li>
30009+
</ol>
30010+
</li>
30011+
30012+
<li><p><i>Navigate to the resource</i>: <span>Navigate</span><!--DONAV iframe--> the element's
30013+
<span>nested browsing context</span> to <var>resource</var>.</p></li>
2996130014
</ol>
2996230015

2996330016
<p>Any <span data-x="navigate">navigation</span> required of the user agent in the <span>process
@@ -30032,7 +30085,12 @@ interface <dfn>HTMLIFrameElement</dfn> : <span>HTMLElement</span> {
3003230085
<var>element</var>'s <span>nested browsing context</span> is again <span
3003330086
data-x="navigate">navigated</span>, that will further <span>delay the load event</span>.</p>
3003430087

30035-
<p>The <code>iframe</code> element <span>potentially delays the load event</span>.</p>
30088+
<p>Each <code>iframe</code> element has an associated <dfn>current navigation was lazy
30089+
loaded</dfn> boolean, initially false. It is set and unset in the <span>process the
30090+
<code>iframe</code> attributes</span> algorithm.</p>
30091+
30092+
<p>An <code>iframe</code> element whose <span>current navigation was lazy loaded</span> boolean is
30093+
false <span>potentially delays the load event</span>.</p>
3003630094

3003730095
</div>
3003830096

@@ -30324,6 +30382,25 @@ interface <dfn>HTMLIFrameElement</dfn> : <span>HTMLElement</span> {
3032430382
used when <span data-x="process the iframe attributes">processing the <code>iframe</code>
3032530383
attributes</span>. <ref spec=REFERRERPOLICY></p>
3032630384

30385+
<p>The <dfn data-x="attr-iframe-loading"><code>loading</code></dfn> attribute is a <span>lazy
30386+
loading attribute</span>. Its purpose is to indicate the policy for loading <code>iframe</code>
30387+
elements that are outside the viewport.</p>
30388+
30389+
<p>When the <code data-x="attr-iframe-loading">loading</code> attribute's state is changed to the
30390+
<span data-x="attr-loading-eager-state">Eager</span> state, the user agent must run these
30391+
steps:</p>
30392+
30393+
<ol>
30394+
<li><p>Let <var>resumptionSteps</var> be the <code>iframe</code> element's <span>lazy load
30395+
resumption steps</span>.</p></li>
30396+
30397+
<li><p>If <var>resumptionSteps</var> is null, then return.</p></li>
30398+
30399+
<li><p>Set the <code>iframe</code>'s <span>lazy load resumption steps</span> to null.</p></li>
30400+
30401+
<li><p>Invoke <var>resumptionSteps</var>.</p></li>
30402+
</ol>
30403+
3032730404
<hr> <!-- FALLBACK -->
3032830405

3032930406
<p>Descendants of <code>iframe</code> elements represent nothing. (In legacy user agents that do
@@ -30362,6 +30439,10 @@ interface <dfn>HTMLIFrameElement</dfn> : <span>HTMLElement</span> {
3036230439
must <span>reflect</span> the <code data-x="attr-iframe-referrerpolicy">referrerpolicy</code>
3036330440
content attribute, <span>limited to only known values</span>.</p>
3036430441

30442+
<p>The <dfn><code data-x="dom-iframe-loading">loading</code></dfn> IDL attribute must
30443+
<span>reflect</span> the <code data-x="attr-iframe-loading">loading</code> content attribute,
30444+
<span>limited to only known values</span>.</p>
30445+
3036530446
<p>The <dfn><code data-x="dom-iframe-contentDocument">contentDocument</code></dfn> IDL attribute,
3036630447
on getting, must return the <code>iframe</code> element's <span
3036730448
data-x="concept-bcc-content-document">content document</span>.</p>
@@ -117754,7 +117835,8 @@ interface <dfn>External</dfn> {
117754117835
<code data-x="attr-iframe-allowpaymentrequest">allowpaymentrequest</code>;
117755117836
<code data-x="attr-dim-width">width</code>;
117756117837
<code data-x="attr-dim-height">height</code>;
117757-
<code data-x="attr-iframe-referrerpolicy">referrerpolicy</code></td>
117838+
<code data-x="attr-iframe-referrerpolicy">referrerpolicy</code>;
117839+
<code data-x="attr-iframe-loading">loading</code></td>
117758117840
<td><code>HTMLIFrameElement</code></td>
117759117841
</tr>
117760117842

@@ -119367,7 +119449,8 @@ interface <dfn>External</dfn> {
119367119449
"<code data-x="attr-img-decoding-auto">auto</code>"
119368119450
<tr>
119369119451
<th> <code data-x="">loading</code>
119370-
<td> <code data-x="attr-img-loading">img</code>
119452+
<td> <code data-x="attr-img-loading">img</code>;
119453+
<code data-x="attr-iframe-loading">iframe</code>
119371119454
<td> Used when determining loading deferral
119372119455
<td> "<code data-x="attr-loading-lazy">lazy</code>";
119373119456
"<code data-x="attr-loading-eager">eager</code>"

0 commit comments

Comments
 (0)