-
Notifications
You must be signed in to change notification settings - Fork 429
Option to not reexecute scripts in body? #143
Comments
I'll add my 2 cents here, not only about that issue but in general. I think turbolink should not deal with all edge cases but have conventions, just like Rails. Turbolinks users just needs to adapt their stack to turbolinks' conventions. If it's too hard, maybe this is not the right solution for you? If we deal with all edge cases, we'll end up having reimplemented the whole browser thing, pile of crap code that will be unnecessary complex and less maintainable. This is just my 2 cents! :) Disclaimer: I am not a maintainer and haven't even wrote a single line for turbolinks so take that with a grain of salt, please. That said, I am thankful for all the work that was done for turbolinks. |
I understand your point. For now I just put my script tags into the header. That solves the issue, but at the expense of speed in non-turbolinks environments. For me that's not a problem, but it might be for others. At the end, the question boils down to "where do I put my script tags". Thinking about it again I see three options:
Probably you are right and this doesn't justify a change in turbolinks. Maybe these options should be listed and explained in the readme? |
I don't see the harm in providing an option for exempting scripts from execution after changing the page. It could be implemented with half a line of code. Just have the I can submit a PR if anyone else thinks it's a good idea. |
I agree with @jipiboily. Implementation of executeScriptTags = ->
for script in document.body.getElementsByTagName 'script' when script.type in ['', 'text/javascript'] and not script.getAttribute?('data-turbolinks-run-once')?
copy = document.createElement 'script' |
Yeah, I don't think this is a good idea. The whole point of Turbolinks is to avoid reloading scripts, so trying to optimize for what happens in the body doesn't gel with that. So no thanks on this for now. |
I usually prefer to add script tags at the bottom of the body, for reasons of loading speed. However as far as I understand, with recent changes to turbolinks, all of those tags will be evaluated every time a new page loads. But that can take a long time (and e.g. scripts like jquery-ujs throw errors in that case), and is the reason I wanted turbolinks in the first place.
Is there a way to put scripts into the body and to not evaluate them every time? I actually would have expected
data-turbolinks-track
to behave like that. What do you think about changing its behavior?The text was updated successfully, but these errors were encountered: