To load only the necessary name_of_the_js_file.js file:
-
remove the
//=require_treefromapplication.js -
keep your js file (that you want to load when a specific page is loaded) in the asset pipeline
-
add a helper in
application_helper.rbdef javascript(*files) content_for(:head) { javascript_include_tag(*files) } end -
yield into your layout:
<%= yield(:head) %> -
add this in your view file:
<% javascript 'name_of_the_js_file' %>
Then it should be ok