Lesson 15 of 17 · 5 min read · Updated
Component Virtualization in ASP.NET Core Blazor
On this page
Introduction
Component virtualization is a technique for limiting UI rendering to only the visible parts of a long list. This dramatically improves performance when rendering large data sets.
Without virtualization, rendering 10,000 items would create 10,000 DOM elements. With virtualization, only the visible items (typically 10-20) are rendered, plus a small buffer.
When to Use Virtualization
| Scenario Recommendation | |
| < 100 items | Regular foreach is fine |
| 100 - 1,000 items | Consider virtualization |
| > 1,000 items | Strongly recommended |
The Virtualize Component
The Virtualize<TItem> component is a built-in Blazor component that efficiently renders lists by only creating DOM elements for visible items.
Important: The Virtualize component requires an interactive render mode to function. It will not work with static server-side rendering (SSR).Render Mode Requirement
The Virtualize component needs interactivity to handle scroll events. Add one of the following render modes to your page:
Or for WebAssembly:
| Render Mode Description | |
InteractiveServer | Server-side interactivity via SignalR |
InteractiveWebAssembly | Client-side interactivity via WebAssembly |
InteractiveAuto | Starts with Server, then switches to WebAssembly |
Basic Usage
Using Items Property
The simplest way to use virtualization with an in-memory collection:
Important: The container must have a fixed height and overflow-y: auto for virtualization to work.ItemsProvider for Async Loading
For large datasets, use ItemsProvider to load items on-demand:
ItemsProviderRequest Properties
| PropertyTypeDescription | ||
StartIndex | int | Index of the first item to load |
Count | int | Number of items requested |
CancellationToken | CancellationToken | Cancellation token for the request |
ItemsProviderResult Constructor
Placeholder Template
Show a loading indicator while items are being fetched:
Empty Content Template
Display a message when the collection is empty:
Configuring Item Size
The ItemSize parameter specifies the approximate height (in pixels) of each item:
| PropertyDefaultDescription | ||
ItemSize | 50 | Height of each item in pixels |
Tip: Set ItemSize to match your actual item height for smoother scrolling.Configuring Overscan
The OverscanCount parameter specifies how many extra items to render above and below the visible area:
| Property Default Description | ||
OverscanCount | 3 | Number of extra items to render outside the viewport |
Higher values:
- ✅ Smoother scrolling experience
- ❌ More memory usage
Lower values:
- ✅ Less memory usage
- ❌ May see brief flashes during fast scrolling
SpacerElement Customization
Customize the spacer element used for scroll calculations:
Useful for HTML tables where spacers need to be <tr> elements.
Refreshing Data
Call RefreshDataAsync() to reload the data:
Complete Example with All Features
Performance Comparison
Without Virtualization (10,000 items)
- ❌ Creates 10,000 DOM elements
- ❌ Slow initial render (seconds)
- ❌ High memory usage
- ❌ Sluggish scrolling
With Virtualization (10,000 items)
- ✅ Creates ~20-30 DOM elements
- ✅ Fast initial render (milliseconds)
- ✅ Low memory usage
- ✅ Smooth scrolling
Common Issues and Solutions
| Issue Cause Solution | ||
| List is empty/not rendering | Missing render mode | Add @rendermode InteractiveServer or InteractiveWebAssembly |
| Items don't scroll | Container has no height | Add height and overflow-y: auto to container |
| Blank spaces appear | ItemSize doesn't match actual | Set ItemSize to match your item height |
| Flashing during scroll | OverscanCount too low | Increase OverscanCount |
| Items reload constantly | Missing CancellationToken | Use request.CancellationToken in async calls |
Summary
| Parameter Type Default Description | |||
Items | ICollection<TItem> | - | In-memory collection |
ItemsProvider | ItemsProviderDelegate<TItem> | - | Async data provider |
ItemContent | RenderFragment<TItem> | - | Template for each item |
Placeholder | RenderFragment<PlaceholderContext> | - | Loading template |
EmptyContent | RenderFragment | - | Empty state template |
ItemSize | float | 50 | Item height in pixels |
OverscanCount | int | 3 | Extra items to render |
SpacerElement | string | "div" | Spacer element type |