Wrong Javascript order: Undefined variable: jQuery Since I moved all scripts form the header to the bottom of the page (in the template file of my theme) I have the problem that some scripts of contributed modules (chosen and device geolocation from smart ip) are added before the JQuery library. Using Jquery this leads to an error:

Undefined variable: jQuery


What can I do to get the right order and what could be the reason of the fact that the order is only wrong when the scripts are added at the bottom of the page and not in the header?
Modules, via drupal_add_js() can define the 'scope' and 'weight'. The 'scope' defaults to header, so unless you change this via drupal_add_js() in your template.php file, you can't move print $scripts from your header, or you'll have this problem with, likely, most contrib modules.

To change this, you could do something like this in yourtheme_preprocess_page($vars):

$js = drupal_add_js();
$newJs = array()
foreach ($js as $s) {
  $s['scope'] = 'footer';
  $newJs = $s;
}

drupal_add_js($newJs);