0

I added this line in my-theme.info

scripts[] = js/my-file.js

The files is loads but in last place. I need it to be loaded before all modules js files.

How can I set the weight?

I also tried (same results) in template.php with:

function MY-THEME_preprocess_page(&$variables) {

  $file =  path_to_theme() . '/js/my-file.js';
  $options = array('weight' => -1000);

  drupal_add_js($file, $options);

}
0

1 Answer 1

1

You can add the scope (header/footer) where to load the JS and also add a weight.

Example options:

$options = array('type' => 'file', 'scope' => 'header', 'weight' => 5));

Play around with these to get the file loaded on the right position that suits your needs. For more detailed information check the documentation.

1
  • To add to this, the 'scope', 'even_page' and 'group' options are considered before weight, so your options should place the js in the 'header' and JS_LIBRARY in addition to a negative weight $options = array('type' => 'file', 'scope' => 'header', 'group' => JS_LIBRARY, 'every_page' => TRUE, 'weight' => -999)
    – thumbson
    Feb 12, 2015 at 17:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.