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.
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.
Lazy loading
Defers the image request until it is close to the visible area.
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.
Virtualization
Limits the number of elements in the DOM. It complements lazy loading but addresses a different layer than file downloads.
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 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.
The image approaches
The browser tracks the element's position and decides when it is close enough to start the request.
Download, decode, paint
The file is downloaded and decoded. Reserving its aspect ratio in advance helps prevent the page from shifting as it loads.
<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.
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.
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.
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.
Render the HTML
In this app, @rendermode InteractiveServer first renders HTML on the server, then establishes an interactive Blazor Server circuit.
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.
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.
Batching or virtualization reduces the initial HTML, DOM node count, and browser workload.
The loading="lazy" attribute reduces the number of requests started immediately.
These approaches do not compete. The Blazor Server demo uses both.
@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.
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.
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.
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.
Reserve the space
Set width/height attributes or an aspect ratio. Bootstrap .ratio reserves space in the gallery below.
Deliver the right variant
Use smaller thumbnails, modern formats, and srcset/sizes. Cropping with CSS cover does not optimize the file.
Describe the image
Meaningful photos need useful alt text. Decorative images can use an empty alt; deferred loading is not a substitute for accessibility.
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.
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.
1500 images.
Load them on demand.
Choose a local or online image source, then choose how cards are rendered. The everyday-web demo assigns image URLs shortly before cards approach the viewport, then lets the browser apply loading="lazy". Blazor Server also appends cards in batches.
How the online sets are built: Unsplash returns random photos in batches of up to 30; Pexels returns curated pages that are sampled at random. The server de-duplicates the results and keeps landscape originals that are at least 2,048 × 1,080 pixels, then displays exactly 100. CDN URLs are resized to 2,048 pixels wide, and the provider’s own image URLs are retained. The API metadata is cached on the server for 15 minutes; the actual photo bytes are still fetched directly by the browser as it scrolls. Free API keys are required: get an Unsplash application key or a Pexels API key. The missing-key message shows the secure local setup command; deployment uses the server environment variables ImageProviders__Unsplash__AccessKey and ImageProviders__Pexels__ApiKey. Never put keys in browser code or commit them.
IntersectionObserver + loading="lazy"The image counter starts in the browser.




























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































loading="lazy" lets the browser defer the request further.row-cols-1 → 2 → 3 → 4