Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Native lazy-load in Chrome

In June Chrome added support of the loading attribute, but it does not work for me. Image is loading when it's not in viewport.

  1. My network info in DevTools

  2. User-agent: Chrome/75.0.3770.80

  3. Enabled lazy image loading in chrome://flags

  4. My test page:

    <p style="margin-bottom: 1000px;">Please scroll down. The image is below the viewport.</p>
    <p style="margin-bottom: 1000px;">Way to go&hellip;</p>
    
    <h4>Lazy cat loaded lazily</h4>
    <p>If your browser supports native lazy-loading, it loads the first 2 kB of the image in order to display a
        placeholder. Then, it loads the full-size image.</p>
    <p>If your browser does not support native lazy-loading, it loads the lazysizes library and sets the
        <code>img</code>'s <code>src</code> to a low-quality image placeholder, which is also around 2 kB in size. Then,
        it loads the full-size image.</p>
    <div class="alert alert-warning">The native lazy-loading's 2 kB range request do not work from within Codepen.
        However, you can make this work by copying this to an empty HTML file on your computer.</div>
    <!-- <img src="https://demo.tiny.pictures/native-lazy-loading/lazy-cat.jpg?width=500"
        loading="lazy" alt="Lazy cat loaded lazily"> -->
    <img src="images/article/photo.jpg" loading="lazy" alt="Lazy turtle">
    
    
    <script>
        if ('loading' in HTMLImageElement.prototype) {
            console.log('YES');
        } else {
            console.log('NO');
        }
    </script>
    

Can you tell me, am i doing something wrong or this attribute is raw and not working?

like image 288
Riccu Avatar asked Jun 14 '19 08:06

Riccu


People also ask

Does Chrome support lazy loading?

In Chrome 76 onwards, you can use the loading attribute to lazy-load images without the need to write custom lazy-loading code or use a separate JavaScript library.

How do I enable lazy on Chrome?

To disable them, hit the drop-down arrow, adjacent to the features described and choose 'Disabled' option. In the end, restart Google Chrome by closing it manually or hit the Relaunch button to restart the browser and allow changes to take effect. Likewise, switch to 'Enabled' to enable the Lazy Loading, again.

Should I enable lazy loading?

You should always use lazy loading for the images below the fold. As we explained, lazy loading will reduce the real and perceived loading time. User experience will benefit from it — and you users will thank you.

What is loading lazy in HTML?

Lazy loading is a strategy to identify resources as non-blocking (non-critical) and load these only when needed. It's a way to shorten the length of the critical rendering path, which translates into reduced page load times.


Video Answer


1 Answers

  • Chrome 75: you'll need to enable lazy loading with the following flags (more details) + relaunch the browser for them to take effect:
chrome://flags/#enable-lazy-image-loading
chrome://flags/#enable-lazy-frame-loading
  • Chrome 76+: native lazy loading is available by default (source).
like image 102
ludovico Avatar answered Oct 13 '22 03:10

ludovico