Components
← All components

Lazy Frame

stimeo--lazy-frame

Defers a turbo-frame's load until it nears the viewport — or focus reaches it.

  • Rails / Turbo

The stimeo--lazy-frame controller defers a <turbo-frame>'s load until it nears the viewport, to keep the initial render light. Turbo's own loading="lazy" fires on render, not on viewport entry, so this drives an explicit IntersectionObserver with a configurable rootMargin for early loading, plus a focus fallback so keyboard / assistive-tech users trigger the load too. The URL is held in the url value (not on src) so Turbo does not load it eagerly; when the frame intersects (within rootMargin) or focus enters it, the controller writes url to src — which starts the Turbo load — marks data-lazy-loaded, and emits load. With once (default) it then stops observing; otherwise re-entry asks Turbo to reload the frame. Behavior only — the load and the frame's content are Turbo's / the server's job, and the loading UI belongs to Frame Loading State. The trigger is idempotent (data-lazy-loaded guards a double load and is honored on a Turbo cache restore), and the observer and focus listener are released once loaded (when once) and on disconnect (Turbo navigation included).

running

Scroll down — the frame below holds its URL and only loads once it enters the viewport.

Not loaded — scroll down to load