DEV Community

Discussion on: A super simple implementation of Infinite Scrolling

Collapse
 
thepeoplesbourgeois profile image
Josh

Nice work! Have you seen the IntersectionObserver API? It might allow you to simplify this code even further 😁

Collapse
 
sakun profile image
sakun

Ah that looks cool. Will be sure to check that out, thanks!

Collapse
 
abhishekcghosh profile image
Abhishek Ghosh

Would strongly second checking out the IntersectionObserver API. Scroll handlers can come with a lot of performance bottlenecks (even if debounced) in execution that blocks the main thread (js is single threaded in nature), slowing everything else on the page .. you might see stuff work smoothly on a developer desktop but when you test on a low end device like an average phone (what your users may be using), you'll see frame drops and jank :( IOs provide async ways to solve problems like this and has been a great addition to the web! If you absolutely need to use scroll listeners, try exploring if "passive" scroll listeners will work for you.