(function(){ var imgs = document.querySelectorAll('img:not([loading])'); imgs.forEach(function(img, i) { if (i >= 2) { img.setAttribute('loading', 'lazy'); } }); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { var newImgs = node.tagName === 'IMG' ? [node] : node.querySelectorAll('img:not([loading])'); newImgs.forEach(function(img) { img.setAttribute('loading', 'lazy'); }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })();