Course contentsShow
← Web Development
Lesson 2102 of 2,98238. JavaScript Performance in the BrowserFree lesson

Overscan and Buffer Items

Rendering extra items above and below the visible area to prevent blank content during fast scrolling.

Overscan and Buffer Items

You'll learn how rendering extra items outside the visible viewport prevents blank spaces during fast scrolling.

The Problem with Strict Visible-Only Rendering

When you implement virtual scrolling (as covered in previous lessons), you calculate which items are visible and render only those. But there's a catch: during fast scrolling, users can scroll faster than your rendering engine can keep up. This creates a brief moment where blank content flashes on screen—a jarring experience.

What is Overscan?

Overscan (or buffer items) means rendering a few extra items above and below the visible viewport boundaries. Think of it like a safety margin.

Analogy: Imagine you're reading a book through a small window that shows 10 lines at a time. If you move the window up quickly, you'd briefly see blank page edges. But if the book always keeps 2 extra lines printed above and below your window (even though you can't see them yet), those lines are ready the instant you scroll.

How It Works

If your visible range is items 20-30, instead of rendering exactly those, you might render items 18-32—adding 2 buffer items on each end. When the user scrolls down, items 31-32 are already rendered and immediately visible, eliminating the blank flash.

Configuring Overscan

The overscan count is typically configurable. Common values are 1-5 items per side, depending on:

  • Item height: Taller items need less overscan
  • Scroll speed expectations: Fast scrollers need more buffer
  • Performance budget: More items = more DOM nodes

Key Takeaway: Overscan renders extra items beyond the visible area as a buffer, trading slightly more DOM nodes for smoother, flash-free scrolling during rapid user interactions.