DEV Community

no momo
no momo

Posted on

Rendering High-Density Data: Virtual Lists vs. Pagination

If you navigate to the tier list or the word list on kanto-tactics.com, you'll see a lot of data. A full tier list contains every unit in the game, their stats, and their synergies.

Rendering 500+ complex DOM nodes (with images, tooltips, and CSS grids) at once will cause layout thrashing and jank, especially on low-end mobile devices.

The DOM is Expensive
Every DOM node consumes memory. If your list has 1,000 items, and each item is a <div> with nested <img> and <span> tags, you are creating thousands of nodes. The browser has to calculate CSS for all of them, even if they are off-screen.

The Virtualization Approach
The standard solution is a virtual list (windowing). You only render the items currently visible in the viewport, plus a small buffer (e.g., 5 items above and below). As the user scrolls, you recycle the DOM nodes by updating their content and applying a transform: translateY(...) to simulate scrolling.

// Conceptual virtualization
const itemHeight = 80;
const visibleCount = Math.ceil(window.innerHeight / itemHeight);

function render(scrollTop) {
  const startIndex = Math.floor(scrollTop / itemHeight);
  const endIndex = startIndex + visibleCount;

  const visibleData = allData.slice(startIndex, endIndex);
  // render only visibleData to the DOM
}
Enter fullscreen mode Exit fullscreen mode

The Trade-off: Accessibility and SEO
Virtualization breaks native Ctrl+F (browser find). If the user searches for a specific unit, the browser won't find it because it's not in the DOM. It also hides content from search engines.

A simpler alternative for static sites is Pagination or "Load More" buttons. It keeps the DOM light, maintains accessibility, and still allows search engines to crawl the content via links.

Whether you choose virtualization or pagination depends on the data. If it's a searchable directory, pagination is often safer. If it's an infinite feed, virtualize.

You can inspect the DOM weight of the tier list at kanto-tactics.com/tier-list. Use the Chrome DevTools Performance tab and watch the "Recalculate Style" and "Layout" times.

Top comments (0)