Hotwire Discussion

Skip turbo-frames that are not in the current scope

I saw few examples where I’m positioned in the turbo-frame A, and after some action within A navigation scope, I receive rendered HTML with frames A, B, C, D. Content from turbo-frame A is extracted and old content in A is replaced with the new one. B, C, D turbo-frames required DB queries, server-load, bandwidth, they were even rendered and never used. Do you think this could be optimized in one of the future versions?

Is it possible to extend turbo-frame functionality, so it renders only turbo frame that has the same ID as turbo-frame from navigation scope, or from the target attribute? I suppose this could be done via additional

  • HTTP header with turbo_frame_id navigation scope

  • set instance variable based on that header

  • guard clause in turbo_frame_tag based on turbo_frame_id == instance variable

The idea behind this is to respond with turbo_frame that is actually needed, and not with the whole page and multiple turbo-frames.


And it might also be helpful to extend the target attribute on turbo_frame_tag so it accepts array of frames = [A, C]. E.g. If A-frame is all messages, and C frame is form for a new message. In that case, we would only refresh all messages and the form. Navigation B would stay untouched.

Thank you, Filip