Will a display:none, loading="lazy" image load with the page?

1 week ago 13
ARTICLE AD BOX

I tested the snippet below in FireFox

#foo { display: none; } <img src="https://images.pexels.com/photos/32710703/pexels-photo-32710703.jpeg" loading="lazy" id="foo">

and it did not send a request to the image if it was display: none however, it it was not display: none then the request has been sent. The behavior is confirmed by this quote:

Using loading="lazy" can prevent images being loaded when they aren't visible but are within the calculated distance. These images might be behind a carousel or hidden by CSS for certain screen sizes. For example, Chrome, Safari, and Firefox don't load images using display: none; styling, either on the image element or on a parent element. However, other image hiding techniques, such as using opacity:0 styling, still cause the browser to load the image. Always test your implementation thoroughly to make sure it's acting as intended.

Source.

Read Entire Article