Enabling lazy-loading images on a Blogger website can help improve the loading time of your pages, as images are only loaded when they are in the viewport (visible on the screen) of the user. Here are the steps to enable lazy-loading images on a Blogger website:
- Log in to your Blogger account and go to the "Theme" section in the left sidebar.
- Click on "Edit HTML" to access the code editor.
- Right before the line, add the following code:
- Save the changes and view your blog to confirm that lazy-loading images are now enabled.
<b:if cond='data:blog.pageType == "item"'> <script type='text/javascript'> // Lazy-load images document.addEventListener('DOMContentLoaded', function() { var lazyImages = [].slice.call(document.querySelectorAll('img[data-src]')); if ('IntersectionObserver' in window) { let lazyImageObserver = new IntersectionObserver(function(entries, observer) { entries.forEach(function(entry) { if (entry.isIntersecting) { let lazyImage = entry.target; lazyImage.src = lazyImage.dataset.src; lazyImage.removeAttribute('data-src'); lazyImageObserver.unobserve(lazyImage); } }); }); lazyImages.forEach(function(lazyImage) { lazyImageObserver.observe(lazyImage); }); } else { // Fallback for browsers without IntersectionObserver lazyImages.forEach(function(lazyImage) { lazyImage.src = lazyImage.dataset.src; lazyImage.removeAttribute('data-src'); }); } }); </script> </b:if>
0 Comments
Please do not enter any spam link in the comment box.