2

I want to customize the order of loading javascripts in drupal 7. I am using Bartik theme. If I want to add a new JS and load it somewhere in between those list. How can I achieve the same? Thanks

2 Answers 2

1

You have to use drupal_add_js function

The second parameter is $options, that you can pass the group of your Javascript file

  • JS_LIBRARY: Any libraries, settings, or jQuery plugins.
  • JS_DEFAULT: Any module-layer JavaScript.
  • JS_THEME: Any theme-layer JavaScript.

Also you can pass the weight of your script to define the order you want.

Here is an example

drupal_add_js('jQuery(document).ready(function () { 
  alert("Hello!"); });', 
  array('type' => 'inline', 'scope' => 'footer', 'weight' => 5)
);

I recommend you to read this article: Managing javascript in Drupal 7

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

Comments

0

If you want one javascript to get load before the other javascripts then, you can write hook_init() in module file and write drupal_add_js to inculde javascript you want to get load first.

and if the javascripts are external then you can directly use in html.tpl file in whatever order you want to load it.

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.