Fashion & Lifestyle
// Image loading optimization document.addEventListener('DOMContentLoaded', () => { const images = document.querySelectorAll('img[loading="lazy"]'); const observer = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { const img = entry.target; img.src = img.dataset.src || img.src; // Fallback to src if dataset.src is not set observer.unobserve(img); } }); }, { rootMargin: '200px 0px', // Load images 200px before they enter viewport threshold: 0.01 });
images.forEach(img => {
observer.observe(img);
// Add error handling for image loading
img.onerror = () => {
img.src = 'https://via.placeholder.com/400x200?text=Image+Not+Found';
img.alt = 'Image not available';
};
});
});