Lazy Loading Images in HTML
The loading="lazy" attribute in an <img> element tells the browser to defer loading the image until it is about to enter the viewport. This improves page load performance, reduces bandwidth usage, and speeds up rendering for images that are not immediately visible.
Images with loading="lazy" are not fetched until they are near the visible area of the page.
Helps reduce initial page load time, especially for pages with many images.
Supported in most modern browsers without the need for JavaScript.
Can be combined with responsive images and placeholders for better UX.
In short: Use loading="lazy" to defer offscreen images until they are needed, improving performance and reducing unnecessary network requests.
You're adding images to a long blog article. How would you implement lazy loading for them, and what's the one attribute you need?
A teammate added loading='lazy' to every image on a page, including the hero banner. Users complain the hero loads slowly. What's the issue and how do you fix it?
You inspect an image with loading='lazy' in DevTools Network tab and see it never loads, even after scrolling. What are two things you'd check?
Your image gallery uses loading='lazy' but users report a flash of empty space before images appear. What causes this and how do you fix it without removing lazy loading?
After enabling native lazy loading site-wide, your LCP metric regressed on product detail pages. Walk me through how you'd diagnose and resolve this.
You need to support IE11 for a client. How would you implement a fallback lazy-loading strategy that mirrors native behavior?
Design a lazy-loading strategy for an infinite-scroll feed with 200+ product images. How do you balance bandwidth savings, perceived performance, and CLS prevention?
Your team wants to default all <img> tags to loading='lazy' via a base component. What are the risks of this approach, and what guardrails would you put in place?
How would you measure the real-world impact of native lazy loading vs your previous IntersectionObserver-based polyfill across different network conditions?
You're migrating 50+ micro-frontends from a custom JS lazy-loading library to native loading='lazy'. What's your rollout strategy to ensure zero regressions and consistent behavior?
Analytics show native lazy loading hurts conversion on mobile checkout pages due to delayed product image renders. How do you investigate, and what org-wide policy would you propose?
How would you establish a cross-team imaging standard that defines when to use eager, lazy, or fetchpriority='high' — and how do you enforce it in CI/CD?