Tuesday, November 24, 2026SubscribeMastheadAbout
Cali ReporterCalifornia · National · West Coast · Good News

Advertisement

Technology

Lazy Loading Images: Best Practices for Web Performance

Lazy loading images is a common technique to improve page load times, but it requires careful implementation to avoid negatively impacting user experience. According to a Dev.to article, certain images should not be…

Portrait of Benjamin Boyce
Artificial Intelligence & Technology · November 21, 2026
Share

AI-generated editorial illustration from an imagined camera angle.
AI-generated editorial illustration from an imagined camera angle. Source image: dev.to.

Lazy loading images by adding the attribute loading="lazy" to every <img> tag on a category page is often seen as a straightforward way to improve performance. However, this approach can be counterproductive for certain images that are immediately visible to users upon page load. According to a source from Dev.to, lazy loading tells the browser to delay fetching an image until it is about to scroll into view, which is beneficial for images further down the page but harmful for those that are visible without scrolling (Dev.to, 1). [1]

The most critical images, such as the hero banner or the first row of product cards, should be loaded eagerly rather than lazily. These images are often the Largest Contentful Paint (LCP) elements, and their delayed loading can significantly impact page performance. The source highlights that the hero banner, which is typically the LCP element, should not be lazy loaded as it delays the LCP for no benefit (Dev.to, 1). [1]

To ensure a smooth user experience, developers should prioritize the loading of images that are visible without scrolling and use attributes such as fetchpriority="high" for these images. Additionally, it is crucial to set width and height attributes for all images to prevent layout shifts caused by lazy-loaded images that arrive without reserved space. These best practices help maintain a stable layout while optimizing performance (Dev.to, 1). [1]

The source discusses the implementation of lazy loading on a category page at RAMO, a hardware store, where pages such as the plumbing section feature long grids of small product photos. This context highlights the importance of correctly identifying which images should be lazy loaded and which should be eagerly loaded to optimize performance without compromising user experience. The hero banner on such pages is typically the Largest Contentful Paint (LCP) element, and lazy loading it would delay the LCP unnecessarily. The first row of product cards on desktop is usually fully visible, while on mobile, the first one or two cards are visible, and these should be loaded eagerly. The main product photo on a product page is almost always the LCP element and should be loaded eagerly with a high fetch priority. [1]

Advertisement

In the implementation details, the source provides an HTML example where the hero image is given a high fetch priority, and the first visible product cards are loaded with default settings, while images further down the page are marked with loading="lazy" and decoding="async". It emphasizes the importance of always setting the width and height attributes (or using CSS aspect-ratio) for images to prevent layout shifts. The source also mentions that in a grid component, images are typically rendered in a loop, and the decision to load images eagerly or lazily can be based on their index within the loop. This approach allows for a more dynamic and responsive image loading strategy. [1]

The source further explains that in frameworks like Next.js, the next/image component defaults to lazy loading, which can be problematic for key images such as the hero or main product photo. To address this, developers should opt out of lazy loading for these images by using the priority prop (or preload in newer versions) to ensure they are loaded first. The source also notes that without providing a real value for the sizes attribute on responsive images, the browser may select a larger image than necessary, which can negatively impact performance. Properly configuring these attributes ensures that images are both responsive and efficiently loaded. [1]

To verify that the lazy loading strategy is correctly implemented, the source recommends using DevTools to run a Lighthouse or Performance panel trace and checking which element is reported as the LCP. If the LCP element has loading="lazy" applied, that indicates an issue that needs correction. In the Network panel, images should start loading early, particularly for the hero and first-row images. Throttling the connection and scrolling through the page can also help confirm that lower-row images appear as the user approaches them, without causing layout shifts. The source also notes that background images and carousels are not covered by the loading="lazy" attribute, requiring additional strategies for optimal performance. [1]

Sources

Dev.to

Prepared with AI assistance from the cited sources.

The Cali Reporter newsletter

The stories worth your time.

California, the country, and what comes next. Join our free newsletter for reporting that keeps you informed.

By joining, you agree to receive the Cali Reporter newsletter. Unsubscribe at any time. Privacy policy.

More in Technology

  • Modern Web Guidance 1.0 and Browser Compatibility

    Modern Web Guidance 1.0, announced by Chrome for Developers on November 10, introduces browser compatibility data to assist coding agents in building web features. The initiative emphasizes the importance of fallback…

  • Apache mod_http2 Vulnerability Detection with Nmap

    A new Nmap scripting module has been developed to detect the Apache mod_http2 vulnerability (CVE-2026-119618), addressing the challenges of identifying affected systems accurately.

  • Securing Remote Vendor Access in Industrial Networks

    Best practices for managing remote vendor access in operational technology (OT) networks emphasize controlled access points, multifactor authentication, and time-bound sessions to reduce cybersecurity risks.

Advertisement