Thursday, October 3, 2013

Rails - Specifying Order in which .js files (in "assets" folder) should be loaded

http://stackoverflow.com/questions/11285941/rails-specify-load-order-of-javascript-files

E.g. To use g.raphael :

Suppose our raphael files are as follows in the "assets" folder -
/assets/raphael/g.dot-min.js
/assets/raphael/g.pie-min.js
/assets/raphael/g.raphael-min.js
/assets/raphael/raphael.js

When the files are loaded, they are loaded in the above order (i.e. order seems to be based on name of the file)
If we want to make rails load raphael.js & g.raphael-min.js first then we have to specify that in application.js file

In application.js:
specify
//= require raphael/raphael
//= require raphael/g.raphael-min
//= require_tree .

Note that both the raphael entries have to be above require_tree entry (and raphael has to be before g.raphael-min).
(It almost seems like require_tree entry should be the last entry in application.js file - have to verify this)

No comments:

Post a Comment

Followers

Blog Archive