Building infinite scroll in Rails 8 without any custom JavaScript using Hotwire's Turbo Frames with lazy loading. The approach uses nested turbo-frame elements where each page's frame contains a lazy-loaded frame pointing to the next page. When the lazy frame enters the viewport, Turbo automatically fetches the next page and swaps in the content. The tutorial covers controller setup with Kaminari pagination, the view template with dynamic frame IDs, and a performance optimization using turbo_frame_request? to skip rendering the full layout for subsequent page requests.
Table of contents
The StrategySTEP 1: The ControllerSTEP 2: The View (The Magic Frame)How It Actually Works (Step-by-Step)STEP 3: Optimization (The Pro Move)Summary214 Impressions