Rails turbolinks download javascript on one page

I have a rails application using turbolinks

on one page, I have to download the script, and I don't want to load it into the whole application

add it to the page, for example

<% content_for :head do %> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> <% end %> 

My problem is that I enter the page through the turbolinks script does not load

how can i load single js on a specific page

thanks!

+6
source share
2 answers

Turbolinks will not update head . This is where the advantage. Download speed will be much faster without rebooting the head. This is why your content_for :head will not work.

In your case, the easiest solution is to place the script tag directly on the page template.

+5
source

Perhaps adding data-no-turbolink to the script tag will help you.

 <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false" data-no-turbolink></script> 
+1
source

Source: https://habr.com/ru/post/952432/


All Articles