iframe-loading-lazy-to-eager.html (2086B)
1 <!DOCTYPE html> 2 <head> 3 <title>Below-viewport iframes with loading='lazy' load when set to 4 loading='eager' or the `loading` attribute is removed</title> 5 <link rel="author" title="Dom Farolino" href="mailto:domfarolino@gmail.com"> 6 <link rel="help" href="https://github.com/whatwg/html/pull/5579"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 </head> 10 11 <script> 12 const t = async_test("Below-viewport iframes with loading='lazy' load when " + 13 "set to loading='eager' or the `loading` attribute is " + 14 "removed"); 15 16 const iframe_1_onload = t.unreached_func("#iframe_1 should not load before " + 17 "the window load event"); 18 const iframe_2_onload = t.unreached_func("#iframe_2 should not load before " + 19 "the window load event"); 20 21 window.addEventListener("load", t.step_func(() => { 22 const iframe_1 = document.querySelector('#iframe_1'); 23 const iframe_2 = document.querySelector('#iframe_2'); 24 25 const iframe_1_promise = new Promise((resolve, reject) => { 26 iframe_1.onerror = reject; 27 iframe_1.onload = resolve; 28 }); 29 30 const iframe_2_promise = new Promise((resolve, reject) => { 31 iframe_2.onerror = reject; 32 iframe_2.onload = resolve; 33 }); 34 35 Promise.all([iframe_1_promise, iframe_2_promise]) 36 .then(t.step_func_done()) 37 .catch(t.unreached_func("The iframes should load successfully")); 38 39 // Kick off the requests. 40 iframe_1.loading = 'eager'; 41 iframe_2.removeAttribute('loading'); // unset the attribute, putting it in 42 // the default (eager) state. 43 })); 44 45 </script> 46 47 <body> 48 <div style="height:1000vh;"></div> 49 <iframe id="iframe_1" 50 src="resources/subframe.html?1" 51 loading="lazy" onload="iframe_1_onload();"></iframe> 52 <iframe id="iframe_2" 53 src="resources/subframe.html?2" 54 loading="lazy" onload="iframe_2_onload();"></iframe> 55 </body>