Posted onEdited onInhtml Symbols count in article: 186Reading time ≈1 mins.
Introduction
How to implement lazy load images in html page?
Use loading=lazy attribute of img tag
With html5, you can use loading="lazy" attribute to lazy load images. This attribute tells the browser to defer loading of the image until it is needed. The browser will load the image when it is about to come into view.
1
<img src="image.jpg" loading="lazy" alt="描述性文字">
For old browsers which do not support loading attribute, you can use JavaScript to implement lazy load images.
1 2
<!-- HTML --> <imgdata-src="image.jpg"class="lazyload"alt="描述性文字">