简体   繁体   中英

Putting Javascript at the end of the file using Rails 3.1 asset pipeline

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.

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

EDIT:

<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而言)。

Not sure if you got the answer for this, but you can include multiple manifest files and set up which files you want at the bottom of the page.

In other words, I could create a footer.js manifest file, tell it to include the scripts you want, and then at the bottom of your view template, include it the same way you do your application.js file with the

<%= javascript_include_tag("footer") %>

tag.

You can read more here-

http://coderberry.me/blog/2012/04/24/asset-pipeline-for-dummies/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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