The UI Virtualization plugin provides efficient rendering of large collections by only creating DOM elements for visible items. This dramatically improves performance when working with thousands of items by maintaining a small, consistent number of DOM elements regardless of collection size.
Performance at Scale: Virtual repeat maintains constant performance whether you have 100 items or 100,000 items, making it essential for data-heavy applications.
How It Works
Instead of creating DOM elements for every item in your collection, virtual repeat:
Calculates visible area: Determines how many items can fit in the scrollable viewport
Creates minimal views: Only renders 2× the visible items (for smooth scrolling)
Manages buffers: Uses invisible spacer elements to maintain proper scroll height
Recycles views: Reuses existing DOM elements as you scroll, updating their data context
Handles scroll events: Efficiently responds to scrolling without expensive DOM operations
Installation
Install the plugin via npm:
npminstall@aurelia/ui-virtualization
Register the plugin in your application:
import{ Aurelia }from'aurelia';import{ DefaultVirtualizationConfiguration }from'@aurelia/ui-virtualization';Aurelia.register(DefaultVirtualizationConfiguration).app(/* your root component */).start();
Basic Usage
Simple List
Use virtual-repeat.for just like the standard repeat, with one important requirement: your container must have a fixed height and overflow: scroll or overflow: auto.
Configuration options
virtual-repeat supports several optional, kebab-cased configuration properties that can be appended after the for statement, separated by semicolons (;):
Option
Description
Example
layout
Sets the scrolling direction. Can be 'vertical' (default) or 'horizontal'.
layout: horizontal
item-height
Explicit pixel height for each repeated item. Overrides the automatic first‐item measurement.
item-height: 40
item-width
Explicit pixel width for each repeated item. Overrides the automatic first‐item measurement.
item-width: 120
variable-height
Enables variable‐height support for vertical layouts. Each item's height is measured individually.
variable-height: true
variable-width
Enables variable‐width support for horizontal layouts. Each item's width is measured individually.
variable-width: true
buffer-size
Multiplier that determines how many extra view sets are kept rendered above/below (vertical) or left/right (horizontal). Default is 2.
buffer-size: 3
min-views
Overrides the auto‐calculated minimum number of views needed to fill the viewport.
min-views: 10
Examples:
Names can be in camelCase (itemHeight, itemWidth, etc.) or kebab-case (item-height, item-width, etc.).
Horizontal Scrolling
The virtual repeat supports horizontal scrolling layouts, allowing you to create efficiently virtualized horizontal lists, carousels, and galleries.
Basic Horizontal Layout
Styling Considerations for Horizontal Layouts
Set overflow: auto and white-space: nowrap on the scrolling container
Use display: inline-block (or similar) on items for horizontal arrangement
Specify both width and height for predictable layout
Horizontal with Configuration Options
Horizontal Infinite Scroll
Use Cases for Horizontal Scrolling
Image galleries
Product carousels
Timeline views
Tag lists
Dashboard widgets
Variable Sizing
The virtual repeat supports variable item sizes, which is useful when items have different heights (vertical) or widths (horizontal).
Variable Height (Vertical Layout)
Variable Width (Horizontal Layout)
Combining Variable Sizing with Other Options
Data-Driven Variable Sizing
Performance Considerations
Measurement overhead: DOM measurement adds cost
Use sparingly: enable variable sizing only when needed
Pre-calculate sizes when possible
Caching: virtual repeat caches measured sizes
Infinite Scroll
The virtual repeat dispatches events to let you load more data when the user scrolls near the top or bottom.
Event Types
Usage Example
Best Practices for Infinite Scroll
Prevent multiple requests with a loading flag
Implement error handling
Show loading indicators
Consider debouncing rapid scroll events
Basic Examples
Vertical div (default)
Horizontal div
Vertical list
Horizontal list
Table Virtualization
For tables, virtual repeat works on table rows while preserving the table structure:
Context Properties
Virtual repeat provides all standard repeat context properties:
Available context properties: $index, $length, $first, $last, $middle, $even, $odd
<!-- ❌ Won't work -->
<div virtual-repeat.for="item of items" if.bind="showItems">
${item.name}
</div>
<!-- ✅ Nest instead -->
<template if.bind="showItems">
<div virtual-repeat.for="item of items">
${item.name}
</div>
</template>
<!-- ❌ Won't work -->
<template virtual-repeat.for="item of items">
<div>${item.name}</div>
</template>
<!-- ✅ Use a concrete element -->
<div virtual-repeat.for="item of items">
${item.name}
</div>