I am using pace.js library and its documentation says, that I need to include their JS/CSS file as early as possible. http://github.hubspot.com/pace/ . I did it and now my application.html.erb looks this way:
<head>
<%= javascript_include_tag "pace.min" %>
<%= stylesheet_link_tag "pace", :media => "all" %>
<title>My site</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
</head>
But when I look at generated HTML I can see that pace is being included twice.
First time at the begining of <head> and second time in place of javascript_include_tag "application"
How to prevent it?
First time pace.js is included because of <%= javascript_include_tag "pace.min" %> statement where you have explicitly specified to include pace.js library.
And second time because of the following statement in application.js
//= require_tree .
This statement means that include all the js files in the current directory of application.js(app/assets/javascripts) and I am guessing that you have kept pace.js in the same directory which is why it is being included again.
EDIT
Use stub directive in application.js, if you want to exclude pace.js from the asset bundle and include it explicitly in <head>. This way pace.js would only be included once.
//= stub pace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With