Take the 2-minute tour ×

here is mobile.js

//= require jquery
//= require iui
//= require faye-updater
//= require anonymous-chat
//= require anonymous-vote
//= require_self

here is how i include scripts

<%= content_for :head do %>
<%= javascript_include_tag "#{Settings.faye.address}/client.js" %>
<%= javascript_include_tag "mobile" %>
<% end %>

and what i get after recompiling assets: mobile....js starts from

function launch_faye_updater....

this is function from the faye-updater.js and it must be included after jquery and iui. And it does not work because of wrong inclusion order. How to make Rails include assets in right order ?

UPD: This is in production mode Rails 3.2.8

share|improve this question
What version of Rails are you using? It looks like you're doing the right thing to compile the assets in the right order. Have you added mobile.js to be compiled in the environments configuration? Set the config value config.assets.precompile += %w( mobile.js ) –  joonty Nov 22 '12 at 9:29
yes, i have added just this config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/ to precompile everything i can, and rails would throw an error if i would not precompile mobile.js. Rails version is 3.2.8 –  s9gf4ult Nov 22 '12 at 9:38
That doesn't seem right - you only need to precompile the top level assets, ones that aren't included by other master assets. Try just adding mobile.js. –  joonty Nov 22 '12 at 10:19
I know this is not right, but what the difference if mobile.js precompiles too ? And how can it affect to inclusion order ? –  s9gf4ult Nov 22 '12 at 10:30
Since mobile.js includes other js files, precompiling that will (or should) combine jquery, iui, faye-updater, anonymous-chat, anonymous-vote, then itself. Adding that regex to the precompile list would compile every file, meaning that some of those javascripts are compiled twice. That could be causing the effect that you're seeing with the assets. –  joonty Nov 22 '12 at 10:35
add comment

2 Answers

Where is launch_faye_updater being called from?

I'm guessing you can fix this problem by moving this line:


Down below the other include, like so:

<%= javascript_include_tag "mobile" %>

(You may also want to consider creating a new compiled JS file with these two files in it.)

share|improve this answer
launch_faye_updater is from faye-updater and #{Settings.faye.address}/client.js must be included before faye-updater –  s9gf4ult Nov 22 '12 at 9:36
What makes you say it doesn't work? Are you getting a JavaScript error when you try to load the page? Could you post that error? (@s9gf4ult) –  drewinglis Nov 22 '12 at 9:45
Erros is: "Uncaught ReferenceError: $ is not defined" as expected, because of jquery is not included when launch_faye_updater is called first. –  s9gf4ult Nov 22 '12 at 9:50
Is that error coming from the client.js file, or the mobile.js file? –  drewinglis Nov 22 '12 at 9:53
it comes from mobile.js –  s9gf4ult Nov 22 '12 at 10:05
add comment

I had the same problem with my jquery, bootstrap and application dependencies. You can deliver all your JS modules in preferred order in Rails 3.1+. In your example you want to have jquery.js included before mobile.js.

First, remove jquery from your mobile.js file.

Then you need to add following line of code to your application.rb:

config.assets.precompile += ['mobile.js', 'jquery.js', 'jquery_ujs.js']

At this moment you have everything precompiled and ready to use. Your mobile.js doesn't include jquery, so you can include it in your preferred order:

<%= javascript_include_tag "jquery" %> 
<%= javascript_include_tag "mobile" %>

And that's it!

share|improve this answer
add comment

Your Answer


