Adding JavaScript before drupal.js I am trying to add jQuery to my page (it is not being added by default). The file is adding to the page but after drupal.js causing the error:

SCRIPT5009: 'jQuery' is undefined 
drupal.js, line 5 character 1 


The code that adds drupal.js to the page in common.inc

...
'misc/drupal.js' =&gt; array(
          'data' =&gt; 'misc/drupal.js',
          'type' =&gt; 'file',
          'scope' =&gt; 'header',
          'group' =&gt; JS_LIBRARY,
          'every_page' =&gt; TRUE,
          'weight' =&gt; -1,
          'preprocess' =&gt; TRUE,
          'cache' =&gt; TRUE,
          'defer' =&gt; FALSE,
        ),
...


In my module hook_init I have:

  drupal_add_js('misc/jquery.js', array(
    'group' =&gt; JS_LIBRARY,
    'weight' =&gt; -20,
    'cache' =&gt; TRUE,
  ));


I would think with a lower weight it would load before drupal.js?

The header of the page contains the following scripts:

&lt;script type="text/javascript" src="http://mysite.com/misc/drupal.js?mqdxrf"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://mysite.com/misc/jquery.js?mqdxrf"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://mysite.com/misc/jquery.once.js?mqdxrf"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://mysite.com/sites/default/files/languages/nl_c9aC92_wtuULa79-hTFcGPM53oqk1yKwciOa_Q3yO28.js?mqdxrf"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://mysite.com/sites/all/modules/lang_dropdown/msdropdown/jquery.dd.js?mqdxrf"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://mysite.com/sites/all/modules/lang_dropdown/lang_dropdown.js?mqdxrf"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="http://mysite.com/sites/all/modules/devel/devel_krumo_path.js?mqdxrf"&gt;&lt;/script&gt;
In the end I got it working by changing the code to:

  drupal_add_js('misc/jquery.js', array(
    'group' =&gt; JS_LIBRARY,
    'weight' =&gt; -20,
    'every_page' =&gt; TRUE,
    'cache' =&gt; TRUE,
    'scope' =&gt; 'header',
  ));
  drupal_add_js('misc/jquery.once.js', array(
    'group' =&gt; JS_LIBRARY,
    'weight' =&gt; -19,
    'every_page' =&gt; TRUE,
    'cache' =&gt; TRUE,
    'scope' =&gt; 'header',
  ));


This then meet the rules on https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_js/7


First by scope, with 'header' first, 'footer' last, and any other scopes provided by a cust om theme coming in between, as determined by the theme.
Then by group.
Then by the 'every_page' flag, with TRUE coming before FALSE.
Then by weight.
Then by the order in which the JavaScript was added. For example, all else being the same, JavaScript added by a call to drupal_add_js() that happened later in the page request gets added to the page after one for which drupal_add_js() happened earlier in the page request.