使用Rails 3.1资产管道将Javascript放在文件的末尾 [英] Putting Javascript at the end of the file using Rails 3.1 asset pipeline

查看:174
本文介绍了使用Rails 3.1资产管道将Javascript放在文件的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时在繁重的客户端Javascript中,我们将标记放在HTML文件的末尾,以便在之后加载Javascript时首先显示内容。

Sometimes in heavy client side Javascript we put the tags at the end of the HTML file so that the content is displayed first while Javascript is loaded afterwards.

是否可以使用Rails 3.1资产管道进行此操作?

Is it possible to do this using Rails 3.1 assets pipeline?

编辑:

<html>
<head>
   <%= javascript_include_tag "application" %>
</head>

<body>
<!-- all the page content goes here -->


<!-- we include these at the bottom to ensure the html loads first and the javascript is loaded afterwards. How can we achieve this through rails asset pipelining? -->

<script src="/some_other_assets/first_file.js"></script>
<script src="/some_other_assets/second_file.js"></script>
<script src="/some_other_assets/third_file.js"></script>

</body>

</html>


推荐答案

是的,你可以用Rails 3.1做到这一点 - 它在您的视图/布局中放置 javascript_include_tag 行的地方没有任何区别(就Rails而言)。

Yes, you can do this with Rails 3.1 — it doesn't make any difference (as far as Rails is concerned) where you put your javascript_include_tag lines in your view/layout.

这篇关于使用Rails 3.1资产管道将Javascript放在文件的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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