1

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>

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

7 Comments

I am not using javascript_include_tag. It's the asset pipeline which will combine all the js files. Is there a way to tell it to include certain files on the top and the rest on the bottom?
You're not making any sense to me.
does the addition in the question helps?
Yes: you're doing it wrong. Those files will not be loaded with the Asset Pipeline. Why don't you use the Asset Pipeline for all of your resources? You can have multiple base files; for example I usually put all vendor libraries into vendor/assets/javascripts and have the Asset Pipeline concat & compress them into a single vendor.js file that can be included before my application.js.
a more detailed and explicit answer to nEEbz's last comment would be helpful.
|
1

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.