Skip to content

What is lazy loading and how and where is it used for images?

Lazy loading is a technique that defers loading images and iframes that are not visible on screen until the user approaches them. The amount of data transferred on the initial load decreases, and the main image arrives sooner. If it is applied to the wrong image, the page slows down.

Nurullah Okatan · Content Writer
· Updated: · 13 min read

What is lazy loading and how and where is it used for images?

Lazy loading is a loading technique that defers downloading images outside the screen until the user approaches them. The page downloads less data on first open, and the images in the first visible area also reach the screen sooner because they do not share bandwidth with the images below.

How does lazy loading work in the browser?

The browser decides when to download an image by checking the loading attribute on the img tag. According to the W3Schools definition, this attribute determines whether the image should load immediately or, if it is outside the viewport, be held until the user approaches it.

Lazy Loading Implementation Methods and Best Practices

There are two values. eager is the default and downloads the image as soon as the page opens. lazy postpones the download until certain conditions are met. If the attribute is not written at all, the browser behaves as if it were eager.

According to the DebugBear explanation, a deferred image starts downloading when the user scrolls the page and gets close to the element. The browser does not wait for the image to enter the screen. It sends the request once the image area comes within a certain distance, so the image is usually ready by the time it becomes visible.

This distance depends on connection speed. According to OpenReplay data, on a 4G connection Chrome starts loading about 1,250 pixels before the image enters the viewport. On 3G and slower connections the distance grows to about 2,500 pixels. Because downloads take longer on slow connections, the browser acts earlier.

The distance threshold is not a value the developer can set; the browser calculates it itself. Other applications related to page structure and image dimensions are covered in Web Design & Development articles.

AI assistant for this topic

Türk Bilişim AI answers your questions instantly
Online
  1. Hi! Ask whatever you're curious about.

How do images affect page weight and load time?

Images are the largest item in the data a page downloads. According to HTTP Archive data cited in the web.dev article, images are the most requested resource type on most sites and usually consume more bandwidth than all other resources combined. According to the same article, sites at the 90th percentile send more than 5 MB of images on both desktop and mobile.

Without lazy loading, all of this data is downloaded while the page opens. Even if a user leaves before scrolling halfway down, the gallery and product photos at the bottom have already been downloaded. Requests that start at the same time share the connection, so the main image above the fold waits in line.

Largest Contentful Paint (LCP) is the time it takes for the largest content element on the page to be painted on screen. In a DebugBear test, when the priority of images below the fold was lowered, the browser loaded the background image much earlier. LCP dropped from 1.6 seconds to 0.8 seconds. Another DebugBear experiment measured a 22% improvement in LCP and a 26% reduction in page weight.

The gains are also visible on the server side. According to a freeCodeCamp article, lazy loading reduces the amount of data transferred on first load, saving bandwidth for both the user and the server. If most visitors do not scroll to the end of the page, the images that are never downloaded never leave the server.

To see the real effect, the page should be measured with the same tool before and after the change; a single test result does not represent the whole site. Turkey's best AI Chatbot & Customer Assistant firm, Türk Bilişim, handles image weight, LCP and server load together in its Performance, Security & SEO service. The firm has worked as a digital agency since 1998 and has been developing artificial intelligence solutions since 2022.

Looking for AI Content & Image Generation?

Which images should not get loading="lazy"?

Images that are visible immediately when the page opens should not receive loading="lazy". W3Schools also recommends applying this value only to images below the first visible area (below the fold).

Things to Consider When Using Lazy Loading

The main image is the LCP element on most pages. If it is deferred, the browser first calculates the page layout, and only after determining that the image is on screen does it start downloading it. This delay directly extends the LCP time. That is why the logo, the homepage banner, the first product photo and the cover image of a blog post should remain eager.

In product lists and blog archives, the boundary is drawn according to the cards that fit in the first screen. On desktop the first row, and on mobile the first one or two cards, are usually visible on open. These cards load immediately, while the rows below are deferred. Since the screen size varies by device, it is safer to keep the cards visible on the largest common screen as eager rather than setting the boundary for a single device.

On e-commerce sites, category pages contain dozens of product images. Here the rule is written once in the template: if the card's position is below a certain number, no attribute is added; if it is above, lazy is added. Then the page is measured separately on mobile and desktop, and it is checked that the LCP element is not deferred.

Difference between the HTML attribute and a JavaScript library

The browser's own loading attribute keeps the image address in the HTML and leaves the decision to the browser. A JavaScript library hides the image address and, after a script that watches scrolling runs, writes the address back.

The source of the delay is this intermediate step. According to the DebugBear explanation, lazy loading with a library requires the JavaScript code to be downloaded before the image loads. If the user scrolls quickly, the images may appear on screen late.

Criterionloading="lazy" attributeJavaScript library
Extra codeNot requiredThe script must be downloaded and run
Loading decisionThe browser decides based on connection speedSet by the library's configuration
Image addressVisible in the HTMLOften hidden until the script runs
Iframe supportYesDepends on the library
Use caseStandard imagesCases the attribute does not cover, such as background images

WordPress adds the attribute itself. According to SiteGround, images inserted with the block editor or created with wp_get_attachment_image() get loading="lazy" by default. If a separate lazy loading plugin is also enabled on the same site, the two methods may conflict.

Empty space appears only rarely while scrolling. According to Android Chrome experiments in the web.dev article, 97.5% of deferred images on 4G connections were fully loaded within 10 ms after becoming visible. If an image is given width and height values, its space is reserved in advance and the content does not shift. Their effects on search visibility are discussed separately in the SEO & Search Engine Optimization articles.

Frequently asked questions

Does lazy loading harm SEO?

When the browser's own attribute is used, the image address stays in the HTML, so search engines can find the image. The risk appears with libraries that hide the address until a script runs, and on pages where the main image is deferred and LCP is delayed.

Can lazy loading also be used for iframes?

Yes. According to DebugBear, alongside images, loading="lazy" can also defer loading of iframes until the user approaches them; embedded videos and maps at the bottom of a page are typical examples.

Does a WordPress site need lazy loading enabled separately?

It is not required for images inserted with the block editor. Images in the theme's hand-coded templates and background images should be checked separately.

Does lazy loading make images appear late on mobile?

In most cases it does not, because according to OpenReplay data the browser starts loading images on slow connections at about 2,500 pixels before they enter the viewport. Delays are more often seen on sites that use a JavaScript library.

Looking for AI Strategy & Consulting?
Have a project?

Türk Bilişim · Free Quote

Get a free quote for your AI Chatbots & Customer Assistants project

Leave your number and we will get back to you right away. The call is free.

Read the privacy notice

Nurullah Okatan Content Writer

The editorial desk of a team delivering websites, e-commerce and software projects since 1998.

LinkedInInstagramFacebook

Share this article

Comments

Comments

No comments yet.

Write a comment

Your rating (optional)

Privacy notice

We will send a confirmation link to your email so that your comment can appear.

Türk Bilişim · Digital Transformation Advisor

Online
Hi! Tell us the project or idea on your mind and let’s begin together.
Ask anything, Türk Bilişim AI answers instantly.