<!-- Add this script tag to the head section of your Blogger template -->
<script>
function lazyLoad() {
const elements = document.querySelectorAll('img[data-src], video[data-src]');
elements.forEach(el => {
if (el.tagName === 'IMG') {
el.setAttribute('src', el.getAttribute('data-src'));
} else if (el.tagName === 'VIDEO') {
el.setAttribute('src', el.getAttribute('data-src'));
el.load();
}
el.onload = () => {
el.removeAttribute('data-src');
};
});
}
document.addEventListener('DOMContentLoaded', lazyLoad);
window.addEventListener('scroll', lazyLoad);
window.addEventListener('resize', lazyLoad);
</script>
<!-- Add this class to the images and videos that you want to lazy load -->
<img class="lazyload" data-src="your-image-url.jpg" alt="your-image-alt-text" />
<video class="lazyload" data-src="your-video-url.mp4" controls></video>
<!-- Add this script tag to the end of the body section of your Blogger template -->
<script src="https://cdn.jsdelivr.net/npm/lazysizes@5.3.2/lazysizes.min.js"></script>
THIS UPPER CODE WORKS FOR BOTH VIDEOS AND IMAGES
Comments
Post a Comment