Rails指定javascript文件的加载顺序? [英] Rails specify load order of javascript files?

查看:85
本文介绍了Rails指定javascript文件的加载顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的application.js文件中,我有:

In my application.js file, I have:

//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//= require_tree .
//
//= require .//community_app
//
//= require_tree ../templates/
//= require_tree .//models
//= require_tree .//collections
//= require_tree .//views
//= require_tree .//routers

但生成的html不服从此订单:

but the generated html doesn't obey this order:

<head>
  <title>CommunityApp</title>
  <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/communities.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/home.css?body=1" media="all" rel="stylesheet" type="text/css" />
  <script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/underscore.js?body=1" type="text/javascript"></script>
<script src="/assets/backbone.js?body=1" type="text/javascript"></script>
<script src="/assets/collections/communities.js?body=1" type="text/javascript"></script>
<script src="/assets/community_app.js?body=1" type="text/javascript"></script>
<script src="/assets/home.js?body=1" type="text/javascript"></script>
<script src="/assets/models/community.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
  <meta content="authenticity_token" name="csrf-param" />
<meta content="ktrLMDYSJaU/mmgmzfpxDfMin7OCXga4K5gVIJZHJUI=" name="csrf-token" />
</head>
<body>

在模型之前加载集合,这会在前端出现错误。我怎样才能使它以特定的方式加载js文件?
谢谢

Collections is loaded before the model which gives me error on the front-end. How can I make it so it loads in a specific manner the js files? thanks

推荐答案

你还有一个

//= require_tree .

更高,即加载所有内容,显然按字母顺序排列。删除它(显然确保在其他地方需要一切),你应该没事。你可能能够将你的application.js作为最后一行,但是当两个语句最终需要相同的文件时我不记得指定的行为

Higher up, which is loading everything, apparently in alphabetical order. Remove that (obviously making sure that everything is required elsewhere) and you should be fine. You might be able to make that the last line of your application.js but I don't remember the specified behaviour when two statements end up requiring the same file

这篇关于Rails指定javascript文件的加载顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆