tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

image-loading-lazy-to-eager.html (2029B)


      1 <!DOCTYPE html>
      2 <head>
      3  <title>Below-viewport images 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://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-loading">
      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 images with loading='lazy' load when " +
     13                       "set to loading='eager' or the `loading` attribute is " +
     14                       "removed");
     15 
     16  const img_1_onload = t.unreached_func("#img_1 should not load before the " +
     17                                        "window load event");
     18  const img_2_onload = t.unreached_func("#img_2 should not load before the " +
     19                                        "window load event");
     20 
     21  window.addEventListener("load", t.step_func(() => {
     22    const img_1 = document.querySelector('#img_1');
     23    const img_2 = document.querySelector('#img_2');
     24 
     25    const img_1_promise = new Promise((resolve, reject) => {
     26      img_1.onerror = reject;
     27      img_1.onload = resolve;
     28    });
     29 
     30    const img_2_promise = new Promise((resolve, reject) => {
     31      img_2.onerror = reject;
     32      img_2.onload = resolve;
     33    });
     34 
     35    Promise.all([img_1_promise, img_2_promise])
     36      .then(t.step_func_done())
     37      .catch(t.unreached_func("The images should load successfully"));
     38 
     39    // Kick off the requests.
     40    img_1.loading = 'eager';
     41    img_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  <img id="img_1"
     50       src="resources/image.png?lazy-to-eager-1"
     51       loading="lazy" onload="img_1_onload();">
     52  <img id="img_2"
     53       src="resources/image.png?lazy-to-eager-2"
     54       loading="lazy" onload="img_2_onload();">
     55 </body>