Turbo和Content_for -Rails
我正在尝试仅在特定页面上加载JavaScript。为此,我正在使用<%= yart(:head)%>
在< head>
和页面上的以下内容:
<% content_for :head do %>
<%= javascript_import_module_tag "foo" %>
<% end %>
此功能在单击时起作用第一次指向页面的链接。但是,当我进一步浏览任何地方,然后再返回时,Turbo将头部零件(&lt; script type =“ module”&gt; import“ foo”&lt&lt;/script&gt;
)。因此,此脚本不再执行。
有没有办法告诉Turbo,它不应该“缓存”?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
遇到了相同的问题。必须使用
document.addeventlistener(“ turbo:load”,function(){});
加载jsfoo.js
ran into same problem. had to use
document.addEventListener("turbo:load", function() {} );
to load the jsfoo.js