6

I have a few custom .js files in my public/javascripts folder. The 'javascript_include_tag' adds script tags to the head element. Are these executed in the order in which they appear. If yes, how do I control the order in which these script tags are added to my html.

thanks, ash

1 Answer 1

5

Yes, they are executed in order of appearance, so you just write them in the order you want. If you are currently using javascript_include_tag :all then you can include individual scripts instead to get the order you want:

javascript_include_tag :defaults
javascript_include_tag "script_1"
javascript_include_tag "script_2"
Sign up to request clarification or add additional context in comments.

2 Comments

I would like to use the :recursive => true option therefore I am using the :all option.
@ash34: I don't know of a way to control the order if you're using :all, other than to prefix your file names with numeric indexes to force the order (and that isn't a great option). If you are including all the .js files in all the views, then you could just write individual includes in the layout file to avoid repetition.

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.