Generate js variable before javascript loaded
It is also hard to say if this will work without seeing exactly what you need to do, but you may want to play with the scope, group, and weight options for drupal_add_js().  These may help you get the order that you need.  From the docs


  The exact ordering of JavaScript is as follows:
  
  
  First by scope, with 'header' first, 'footer' last, and any other scopes provided by a custom 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.
  


When I have been in similar situations, I implement a template_preprocess_html(), create some markup, stuff it into $variables, and then output this before the print $scripts in html.tpl.php  I have to use this in some very specific situations where I need to output JS very early in the &lt;head&gt; before CSS and JS is loaded.