6

I have a rails application using turbolinks

one page i should load script, and i don't want load it on all the application

specific add it on page like that

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

my problem is while i enter to page via turbolinks the script doesn't load

how can i load single js on specific page

thanks!

1
  • On the contrary to user3631047's answer, you should try to add data-turbolinks-track="true" in your script tag. I was in the similar situation, and doing so fixed the issue.
    – mc9
    CommentedNov 20, 2014 at 5:12

2 Answers 2

5

Turbolinks will NOT update head. That's where the advantage is. The loading speed will be much faster without head reloading. That's why your content_for :head won't work.

For your case, the simplest solution is to put the script tag directly on page template.

1
  • 1
    But what happen if I enter multiple times to the same page? each time the script will be loaded?CommentedJun 29, 2016 at 15:21
1

Maybe adding data-no-turbolink to your script tag helps you.

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

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.