Reputation: 350
I'm trying to load a javascript only on a certain page. For that I'm using <%= yield(:head) %>
in the <head>
and the following on the page:
<% content_for :head do %>
<%= javascript_import_module_tag "foo" %>
<% end %>
This works when clicking on a link to the page the first time. However when further I navigate anywhere and then go back again, Turbo conserves the head part (<script type="module">import "foo"</script>
). Thus this script is not executed anymore.
Is there a way to tell turbo, that it shouldn't 'cache' this?
Upvotes: 0
Views: 605
Reputation: 317
ran into same problem. had to use document.addEventListener("turbo:load", function() {} );
to load the js
document.addEventListener("turbo:load", function() {
console.log("foo.js loaded");
// more js codes
});
Upvotes: 0