开发者

Load order with javascript_include_tag :all

开发者 https://www.devze.com 2023-01-20 02:23 出处:网络
So I\'ve recently started to include quite a few .js files in to my web application and some of them depend on each other so load order is important.

So I've recently started to include quite a few .js files in to my web application and some of them depend on each other so load order is important.

However rails caching just seems t开发者_JAVA百科o load a all.js file with no particular order to the files.

What's a good way to solve this issue?


You can do as follows

  • First, load the default JavaScript files.
  • Then load other scripts in the order that you want

    <%= javascript_include_tag :defaults %>
    <%= javascript_include_tag "script_1", "script_2", "script_3" %>


The load order depends on your Javascript manifest file. In Rails 3.1 you can go to

app/assets/javascripts/application.js

At the bottom of the file you will see directives for rails how what / how to include files into the Rake pipeline. In the below example, I included a new directive that will include all the files in the directory called "Templates". I also made sure that the Handlebars.js templating file is called before all of the files in the "Templates" directory, otherwise the browser would throw an exception

//= require handlebars
//= require_tree ../templates
//= require_tree .

Hope it helps!


I've been experimenting with the YUILoader Module, it seems pretty nifty, though I am currently frussing about loading up custom modules. It's totally doable, I just couldn't figure it out in 5 mins.

http://developer.yahoo.com/yui/yuiloader/ (YUI2.8.1) http://developer.yahoo.com/yui/examples/yuiloader/index.html

0

精彩评论

暂无评论...
验证码 换一张
取 消