hotwired / turbo

The speed of a single-page web application without having to write any JavaScript
https://turbo.hotwired.dev
MIT License
6.69k stars 423 forks source link

Suggestion : configure a root margin on lazy turboframe intersection observer #1314

Open johndodev opened 2 weeks ago

johndodev commented 2 weeks ago

Hello,

Lazy frames are greats, but loaded only when the frame become visible. I could involve "bumps" when the content fill the frame (we can't always predict the content height before).

In the idea of https://www.stimulus-components.com/docs/stimulus-content-loader, is it possible to think about a way to configure a root margin for the observer ? So we could for example load a frame 50px before starting to be visible !

Ex : <turbo-frame id="turboid" src="..." loading="lazy" root-margin="50px">...</turbo-frame>

pedroaugustofsilva commented 1 week ago

Hi @johndodev.

This article shows how to do that with turbo frames.

It would be good to have it natively on Turbo.