48 CZ-PRG (GMT+1)
US-NYC (GMT-5)
Blazor Web App (Server rendered)

A field guide to image loading

Lazy
loading.

Images do not have to compete for bandwidth as soon as a page opens. The browser can wait until a reader approaches them—and a long list can also be rendered progressively by the app itself.

Native HTML Bootstrap 5.3 1500 local files
01FIRST, LET'S DISTINGUISH THE TERMS

This is not a transition effect.
It is about timing.

Lazy loading defers a resource that is not needed yet—typically an image far below the current viewport. As the visitor scrolls down, the browser starts requesting images that are approaching the viewport. Images below the fold in the Parallax Scrolling and Bento Grid examples on this site already use the same native attribute.

“Progressively” does not necessarily mean exactly one image for every scroll step. The browser chooses when to start a request based on the distance from the viewport, the connection, and its own heuristics; it often starts downloading before the image reaches the screen.

01 / WHEN TO FETCH

Lazy loading

Defers the image request until it is close to the visible area.

02 / HOW THE FILE IS ENCODED

Progressive JPEG

A different concept: one JPEG becomes more detailed through several image scans as it downloads. By itself, this does not delay the start of the download.

03 / HOW MUCH TO RENDER

Virtualization

Limits the number of elements in the DOM. It complements lazy loading but addresses a different layer than file downloads.

02EVERYDAY WEB / NATIVE BROWSER LAZY LOADING

The browser already knows
when to fetch.

For a typical gallery, start with the HTML loading="lazy" attribute. The image remains part of the page, but the browser can defer its network request until the visitor approaches it.

HTML NO LIBRARY
01

HTML declares the source

All images can be present in the document. The loading attribute tells the browser which ones do not need to be fetched immediately.

02

The image approaches

The browser tracks the element's position and decides when it is close enough to start the request.

03

Download, decode, paint

The file is downloaded and decoded. Reserving its aspect ratio in advance helps prevent the page from shifting as it loads.

A MINIMAL OFFSCREEN IMAGEHTML
<img src="/images/000/photo.jpg"
     alt="Describe the image content"
     width="1600" height="1067"
     loading="lazy" decoding="async">

Dimensions or a CSS aspect ratio reserve space before the download completes. decoding="async" can move decoding off the critical rendering path, but it does not reduce the file size.

DON'T LAZY-LOAD THE HERO

Load the first important image early.

A large image in the initial viewport may be the LCP element. Keep it eager or use the default behavior; consider fetchpriority="high" deliberately rather than lazy-loading it.

CROPPING IS NOT COMPRESSION

object-fit: cover does not shrink the file.

CSS fills the frame and may crop part of the photo, but the entire source file is still downloaded. Reduce transfer size with real thumbnails, suitable formats, and srcset/sizes.

03.NET / BLAZOR INTERACTIVE SERVER

Blazor does not change the browser's
rules.

With server-rendered Blazor, separate image downloads from component rendering. The browser still handles the first; the server application can control the second.

01 / SERVER

Render the HTML

In this app, @rendermode InteractiveServer first renders HTML on the server, then establishes an interactive Blazor Server circuit.

02 / BROWSER

Fetch the static asset

When the browser sees <img loading="lazy">, native lazy loading works just as it does in plain HTML. The browser fetches the image directly from its static asset URL.

03 / OPTIONAL

Append more cards

For a long list, the app can render one batch at a time. An IntersectionObserver sentinel requests the next batch, and Blazor appends it through the interactive circuit.

LAYER ARender fewer elements

Batching or virtualization reduces the initial HTML, DOM node count, and browser workload.

LAYER BDefer image downloads

The loading="lazy" attribute reduces the number of requests started immediately.

These approaches do not compete. The Blazor Server demo uses both.

A SIMPLE BLAZOR GALLERYRAZOR
@foreach (var image in images)
{
    <img src="@image.Url"
         alt="@image.Alt"
         loading="lazy"
         decoding="async" />
}

loading="lazy" alone is enough to defer image downloads, even when Razor renders every item at once. For a very long list, add paging, batches, or Virtualize.

WHAT THIS DEMO DOES

The existing ImageFileHelper reads file names and sizes on the server. In “Blazor Server — batches” mode, only the first 24 cards are initially rendered to HTML. As the sentinel approaches the viewport, JavaScript calls a small component method and the server appends more cards. JPEG bytes do not travel over SignalR—the browser fetches them directly from /images/000/… as static files.

For much larger catalogs, read data in pages from the source instead of building all metadata up front. The built-in Virtualize works well for long lists with predictable row heights; a responsive grid with changing column counts needs careful row grouping or custom batching like this example.

04PERFORMANCE, UX & ACCESSIBILITY

Timing is only
one part of the solution.

Lazy loading helps reduce network transfers. A good gallery also needs appropriately sized files, a stable layout, and meaningful content before images finish loading.

01 / LCP

Keep the first image fast

Use lazy loading mainly for images below the fold. Do not hide a critical image near the top of the page behind a deferred request.

02 / CLS

Reserve the space

Set width/height attributes or an aspect ratio. Bootstrap .ratio reserves space in the gallery below.

03 / BYTES

Deliver the right variant

Use smaller thumbnails, modern formats, and srcset/sizes. Cropping with CSS cover does not optimize the file.

04 / CONTENT

Describe the image

Meaningful photos need useful alt text. Decorative images can use an empty alt; deferred loading is not a substitute for accessibility.

05 / BACKGROUND

CSS backgrounds work differently

You cannot add a loading attribute to background-image. Prefer an <img> for important photos; otherwise, visibility observation can control when a background is loaded.

06 / VERIFY

Inspect the network and DOM

Open Network in DevTools, disable the cache, and scroll. Native mode has every card in the DOM; batch mode appends more as you scroll.

Practical rule: for a typical number of photos, start with native loading="lazy". Add batching or virtualization when DOM size or initial HTML is also a problem—not simply because the page contains images.

WEB DESIGN / PERFORMANCE & IMAGESLoad less until it is needed
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.