document.addEventListener("DOMContentLoaded", function() {
if ('loading' in HTMLImageElement.prototype) {
document.querySelectorAll("img").forEach(function(img, index) {
if (img.hasAttribute("loading")) return;
const isHeader = img.closest('header, nav, .navbar');
const isLogo = img.classList.contains('logo') || img.alt.toLowerCase().includes('logo');
const isPriority = index === 0 || isHeader || isLogo;
if (isPriority) {
img.setAttribute("loading", "eager");
img.setAttribute("fetchpriority", "high");
} else {
img.setAttribute("loading", "lazy");
}
img.setAttribute("decoding", "async");
});
} else {
loadLazyLoadingPolyfill();
}
});
function loadLazyLoadingPolyfill() {
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver(function(entries, observer) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
const img = entry.target;
if (img.dataset.src) {
img.src = img.dataset.src;
img.removeAttribute('data-src');
}
observer.unobserve(img);
}
});
});
document.querySelectorAll("img").forEach(function(img, index) {
const isHeader = img.closest('header, nav, .navbar');
const isLogo = img.classList.contains('logo') || img.alt.toLowerCase().includes('logo');
const isPriority = index === 0 || isHeader || isLogo;
if (!isPriority) {
if (img.src && !img.dataset.src) {
img.dataset.src = img.src;
img.src = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB2aWV3Qm94PSIwIDAgMSAxIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxIiBoZWlnaHQ9IjEiIGZpbGw9InRyYW5zcGFyZW50Ii8+PC9zdmc+';
}
imageObserver.observe(img);
}
});
}
}