zoukankan      html  css  js  c++  java
  • [HTML5] Native lazy-loading for the web

    According to HTTPArchive, images are the most requested asset type for most websites and usually take up more bandwidth than any other resource. At the 90th percentile, sites send about 4.7 MB of images on desktop and mobile.

    Currently, there are two ways to defer the loading of off-screen images and iframes:

    In Chrome 76, you can use the loading attribute to completely defer the loading of offscreen images and iframes that can be reached by scrolling:

    <img src="image.png" loading="lazy" alt="…" width="200" height="200">
    <iframe src="https://example.com" loading="lazy"></iframe>
    • auto: Default lazy-loading behavior of the browser, which is the same as not including the attribute.
    • lazy: Defer loading of the resource until it reaches a calculated distance from the viewport.
    • eager: Load the resource immediately, regardless of where it's located on the page.

    The feature will continue to be updated until it's launched in a stable release (Chrome 76 at the earliest). But you can try it out by enabling the following flags in Chrome:

    chrome://flags/#enable-lazy-image-loading

    Notice: In order to make sure the good user experience, recommend to add the size info for the image:

    <img src="..." loading="lazy" width="200" height="200">
    <img src="..." loading="lazy" style="height:200px; 200px;">

    More detail

  • 相关阅读:
    【u026】花园(garden)
    【BZOJ 1040】[ZJOI2008]骑士
    【t100】汤姆斯的天堂梦
    【BZOJ 1038】[ZJOI2008]瞭望塔
    【t096】树的序号
    Java Web整合开发(82)
    2 HTML解析
    T3186 队列练习2 codevs
    T3185 队列练习1 codevs
    T1191 数轴染色 codevs
  • 原文地址:https://www.cnblogs.com/Answer1215/p/11972588.html
Copyright © 2011-2022 走看看