What is the best way to split Javascript assets into scripts that need to load in the header and scripts that need to be in the body?
For instance, right now I have,
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
At the end of my body tag in my main application layout. But I want to include something like,
<%= javascript_include_tag "application_head", "data-turbolinks-track" => true %>
Inside my header tag.
How do I split my application.js
into two separate files to accomplish this? Keep in mind that I need to be able to use direction likes require_tree
in both files so I can't just include each script individually.
copy stuff you want in the head into the application_head directory and the rest into application
app/assets/javascripts/application_head.js:
app/assets/javascripts/application.js:
in config/application.rb, add