I'm using a jquery carousel on my site and getting some errors on some pages. My jquery guru said the cause of the problem is that currently jquery.js gets included after other javascript includes.

Making the jquery.js the first include will fix the problem according to him. How do I change the order of the javascript includes?

  • 1
    If you do a view source, where is jquery.js? I don't recall not seeing it first. – mpdonadio Jan 17 '12 at 1:03
  • in 7th place, after jquery.once.js?v=1.2, drupal.js, admin_devel.js, memcache.js, video.js and extlink.js – uwe Jan 17 '12 at 1:08

Use hook_js_alter to change the order of js presentation.

For example, edit your theme's template.php:

function youtheme_js_alter(&$javascript) {

  $javascript['misc/jquery.js']['group'] = -500;

  $javascript['misc/jquery.js']['weight'] = -500;

| improve this answer | |
  • 2
    thanks. I found the problem, it was caused by a malformed drupal_add_js() function which caused the order of the includes to get messed up. Here is the post for future reference: api.drupal.org/api/drupal/includes--common.inc/function/… Your answer pointed in the right direction (weights), so I'll accept it. – uwe Jan 17 '12 at 5:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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