What I’ve been doing for expensive loading pages is try the lazy loading turbo frame, and having an animation that makes it appear like work is happening. This might make more sense, especially if your background job is in the 1-3 seconds consistently. It looks like that’s what you ended up down, but I may be misreading the code.
I’ve got a sample here (Adding Loading Screen with Turbo • Blogging On Rails) but this makes the dashboard load fast, and you arent fighting a race condition. It’s also simpler from a technical perspective, because you don’t need to add any more front end javascript code.
Jumping in here because I have a jQuery loader in a production app that I’ve been longing to replace.
In the lazy frame scenario, are there any events I could hook into that would replace jQuery’s after success callback? I need to run some processing on the returned remote content, but it only makes sense to do that if that remote content (HTML – sometimes many megabytes) is fully loaded.
Thanks in advance,
Walter
Ye Olde Code:
<script>
$('#preview').load('<%= @title.html.file.url %>', function(){
var anchor = window.location.hash.toString().split('#')[1];
if(!!anchor){
setTimeout(function(){
window.scrollTo({left: $('#' + anchor).offset()['left'], top: $('#' + anchor).offset()['top'] - 20});
},8); // this timing is not waiting for the success function to load the html, but for the DOM to settle
}
});
</script>
I believe this allows this to be quite reusable for one or many different turbo_frames. It’s been in production for a couple days now and we no longer have any issues.
Thanks again for everyone that’s provided help one this one
Interesting solution!
I think you can use the disabled attribute and let the default src do his job. Also, I checked every turbo-cable-stream-source connections, but maybe it’s unnecessary.