ireade / caniuse-embed

📊 Embed realtime data from caniuse.com
https://caniuse.bitsofco.de
325 stars 21 forks source link

Use native lazy loading for fallback images #20

Open makkabi opened 3 years ago

makkabi commented 3 years ago

Right now, if you use the interactive embed and the user has JS activated, the fallback image will still be loaded, despite never beeing shown. This can be easily avoided by adding loading="lazy" to the img-Element. Most browsers support it already, and those wo don't just ignore the attribute: https://caniuse.com/#feat=loading-lazy-attr

I tested this in Firefox and Chromium-Edge, and it works fine. As far as I understand the native lazy-loading attribute can be added without risk or downsides, and we could save time, money, CO2 etc.

Example:

<p class="ciu_embed" data-feature="dialog" data-periods="future_1,current,past_1,past_2" data-accessible-colours="false">
        <picture>
            <source type="image/webp" srcset="https://caniuse.bitsofco.de/image/dialog.webp">
            <source type="image/png" srcset="https://caniuse.bitsofco.de/image/dialog.png">
            <img loading="lazy" src="https://caniuse.bitsofco.de/image/dialog.jpg" alt="Data on support for the dialog feature across the major browsers from caniuse.com">
        </picture>
</p>