Lazy loading delays the download of images, videos and embeds until a visitor is about to scroll to them. Instead of fetching every file on the page at once, the browser loads what is visible first and fetches the rest on demand. On long service pages, product grids and blog posts, this can cut the amount of data a first visit needs and free the connection for the content that matters most.
Done carelessly, though, the same technique can slow down the most important image on the page, cause layout shifts, or hide content from search engines. This guide explains how to implement it correctly, with practical steps for WordPress and custom builds. It belongs to our wider work on search engine optimization and the page performance side of technical SEO.
How lazy loading works
There are two main ways to defer offscreen resources. Modern browsers support a native attribute, and JavaScript libraries offer more control for special cases.
| Method | How it works | Best for |
|---|---|---|
| Native loading=”lazy” | The browser decides when to fetch based on distance from the viewport | Most images and iframes |
| IntersectionObserver script | JavaScript watches elements and swaps in the real source when they approach view | Background images, custom components, video |
| Scroll event scripts | Older libraries listen for scroll events | Avoid: heavier and less reliable for search engines |
The native attribute is the simplest and most dependable choice. Add loading=”lazy” to an img or iframe element, and supporting browsers handle the rest. No script, no dependency, no extra main thread work.
What to lazy load, and what never to
The single biggest mistake is lazy loading the hero image. When the largest visible element waits for the deferral logic, Largest Contentful Paint gets slower, which is the opposite of the goal.
| Element | Lazy load | Reason |
|---|---|---|
| Hero or banner image | No | Usually the LCP element; load it with high priority |
| Logo and above-the-fold icons | No | Visible immediately |
| Images further down the page | Yes | Not needed for the first view |
| YouTube, Vimeo and map embeds | Yes | Heavy iframes with many requests |
| Product grid images below the first row | Yes | Large combined weight |
| Review and social widgets | Yes, or load on interaction | Third-party scripts slow interactivity |
For the hero image, do the reverse: keep it in the HTML as a normal img element and add fetchpriority=”high” so the browser fetches it before less important files.
Implementing it step by step
- Identify the LCP element on each key template. PageSpeed Insights names it in the diagnostics. Make sure it is never lazy loaded.
- Add the native attribute to offscreen images. Use loading=”lazy” on every img below the first screen.
- Set width and height on every image. These attributes let the browser reserve the right space before the file arrives, which prevents layout shift.
- Lazy load iframes. Add loading=”lazy” to video and map embeds, or replace them with a lightweight preview image that loads the player only when clicked.
- Handle background images separately. CSS backgrounds cannot use the native attribute. Use an IntersectionObserver script that adds a class when the section approaches the viewport.
- Keep content in the HTML. Image elements should exist in the page source with a real src or a proper srcset, not only be injected later by script.
- Test on a real mobile device. Scroll quickly through the page and confirm images appear before the visitor reaches them.
Deferring images in WordPress
WordPress adds loading=”lazy” to images and iframes in post content by default, and recent versions try to skip the first large image so the likely LCP element loads normally. That default is helpful, but themes and page builders do not always follow it.
- Check whether the hero is output by the theme or a builder module. If it carries loading=”lazy”, remove the attribute for that element in the builder or with a small filter in the theme.
- Avoid stacking several tools that do the same job. A performance plugin, the theme and WordPress core can all add the attribute, which leads to conflicting behavior.
- When a performance plugin offers to lazy load background images or iframes, test each setting on your key templates before enabling it sitewide.
- For WooCommerce, check category grids and product galleries separately, as gallery scripts often handle images in their own way.
Keeping deferred media search friendly
Googlebot renders pages but does not scroll like a person. It loads the page with a tall viewport, so content that only appears after a scroll event or a click may never be seen. Images Google cannot see cannot rank in image search, and text hidden behind interaction may not be indexed.
- Use the native attribute or IntersectionObserver, both of which work with Google’s rendering.
- Do not lazy load text content, headings or internal links.
- Keep descriptive alt text on lazy loaded images.
- Use URL Inspection in Search Console and view the rendered HTML or screenshot to confirm images are present.
- For infinite scroll product lists, provide paginated URLs as well, so every item is reachable through a normal link.
For bilingual UAE sites, test both the Arabic and English templates. Right to left layouts sometimes use different components or sliders, and one version may defer images differently from the other.
Measuring the result
Compare before and after on the same templates, using both lab tests and real user data.
| Check | Tool | What good looks like |
|---|---|---|
| Total page weight on first load | Browser DevTools network panel | Lower than before, offscreen images not requested |
| LCP element loading | PageSpeed Insights | Hero not lazy loaded, no LCP warning |
| Layout stability | PageSpeed Insights and Search Console | No new CLS issues |
| Rendered content | URL Inspection | Images present in the rendered page |
Frequently asked questions
Can lazy loading hurt my SEO?
It can if it is implemented poorly. Lazy loading the hero image slows Largest Contentful Paint, missing image dimensions cause layout shifts, and scroll-triggered scripts can hide images from Google. The native browser attribute, applied only to offscreen media, avoids these problems and usually improves page speed without affecting indexing.
Should I lazy load every image on the page?
No. Images visible in the first screen, especially the hero, should load immediately and with high priority. Deferral suits images, embeds and widgets further down the page. Applying it to everything delays what visitors see first and can make the page feel slower, even if total download size drops.
Does native lazy loading work in all browsers?
The loading attribute is supported in all major modern browsers, including Chrome, Edge, Firefox and Safari. Older browsers that do not support it simply ignore the attribute and load images normally, so the page still works. That makes the native attribute a safe default without needing a fallback script.
Is lazy loading enough to fix a slow website?
Rarely on its own. It reduces the cost of offscreen media, but slow server response, heavy scripts, unoptimized images and render-blocking CSS often matter more. Treat it as one part of a wider performance plan that starts with hosting, caching and image compression.
Faster first impressions, without side effects
Implemented with care, deferring offscreen media is one of the simplest performance improvements available: the hero loads first, the rest follows as visitors scroll, and nothing is hidden from search engines. The details, especially around the LCP image and image dimensions, are what separate a real gain from a new problem.
If you would like a second pair of eyes on how your templates load images and embeds, we would be glad to review them with you.