0
Challenge · 72Architecture & State
Infinite Scrolling
Perfused in ~35% of apps
A feed can't ship all 10,000 posts on first load — that's a slow page and a huge DOM. Infinite scrolling fetches one page at a time and loads the next only when the user nears the bottom, so the first paint is fast and the network does work only when it's needed.
Core idea. Put an invisible sentinel element at the end of the list and watch it with an IntersectionObserver; when the sentinel scrolls into view you call fetchNextPage(), append the new page, and the sentinel moves down again — repeat until there's no next page.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
FEED VIEWPORT — SCROLL DOWN
1
Post #1
page 0
2
Post #2
page 0
3
Post #3
page 0
4
Post #4
page 0
○ sentinel (scroll to me)
IntersectionObserver
rootviewport
targetsentinel
isIntersectingfalse
1
pages
4
items
0
fetches fired
Scroll the feed until the sentinel enters the viewport. The observer flips isIntersecting to true, which calls fetchNextPage() — the next page loads and appends, pushing the sentinel back down.
↑ play a little first, then dig in