简体   繁体   English

使用javascript_include_tag加载订单:全部

[英]Load order with javascript_include_tag :all

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. 因此,我最近开始在我的Web应用程序中包含很多.js文件,其中一些相互依赖,因此加载顺序很重要。

However rails caching just seems to load a all.js file with no particular order to the files. 但是,rails缓存似乎只是加载了all.js文件,而没有特定的顺序。

What's a good way to solve this issue? 解决此问题的好方法是什么?

You can do as follows 你可以做如下

  • First, load the default JavaScript files. 首先,加载默认的JavaScript文件。
  • 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. 加载顺序取决于您的Javascript清单文件。 In Rails 3.1 you can go to 在Rails 3.1中,您可以转到

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. 在文件的底部,您将看到关于rails的指令,如何/如何将文件包括到Rake管道中。 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 我还确保在“ Templates”目录中的所有文件之前调用Handlebars.js模板文件,否则浏览器将引发异常

//= 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. 我一直在尝试使用YUILoader模块,尽管我目前对加载自定义模块不屑一顾,但这似乎很不错。 It's totally doable, I just couldn't figure it out in 5 mins. 这是完全可行的,我只是在5分钟内无法解决。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM