Turboframe unnecessary queries from out-of-frame pieces

When lazyloading or updating a turboframe, the page that’s requested needs to contain a turboframe with the same ID.

The frame being updated may only be a portion of the page, with lots of other content outside of the frame. That work to prepare the outside-of-frame content still needs to be done, including database queries.

Is that a problem that folks are addressing somehow, or is it more of just a theoretical problem?

1 Like

I’ve been trying to answer the same question and haven’t found a clear answer anywhere. It seems like such an obvious inefficiency that there must be something I’m missing. Is it better for caching to render the whole page? Are you intended to design your routes and controllers in such a way that this has minimal impact?

I think you can solve this by putting each frame into its own partial and only rendering the partial for the requested frame:

if request.headers["Turbo-Frame"] == "my_frame"
  render "_my_frame"
end

But I’m surprised turbo-rails doesn’t make this easier.