Hotwire Discussion

Turbo frame with src but already loaded the first time

I have a turbo frame with src attribute. In the first load of the page I already have the html content loaded inside the frame. Also, I want to be able to reload that frame in the future.

My problem is that, if I have a turbo frame with src attribute, it always load from src the first time. Is there any way to mark as already loaded the frame, so it only uses the src attribute when I invoke the reload() method?



Question, Why you need to execute reload before navigate in the frame? Because the src element is to load the content of the frame async so I’m trying to think on a flow where you don’t need to load the content async but you’ll end up using a reload.

Aparte from that maybe you can try to identify the first load and pause the first request to avoid that unnecessary call and then remove the listener but still sounds a little bit weird to me.


I can load the frame async, but I already have the content because I need it in other parts of the page, so I want to avoid that extra step to win speed.

Pause the first request could work but it also looks weird to me. I wanted something like adding a “loaded” attribute in the same way we have the “loaded” property.

Sounds possible/easy? Thanks!

Can you not just leave the src blank and set it in whatever method you were planning on triggering a reload ?

Store it in a different attribute perhaps and just move it over to src (which will trigger a reload) ?

Yes! I think that would be the best option. Use a data-src attribute, and before reload if src attribute is empty, fill it with data-src if present and then reload.


1 Like