Here's what I'm trying to do to integrate head.js:
i put this code in my template functions.php file
define('THEME', get_bloginfo('template_url'), true);
define('THEME_JS', THEME . '/js/', true);
add_action('wp_print_scripts','head_js_files');
function head_js_files()
{
if (is_admin()) return; //to preserve the admin
global $wp_scripts;
$in_queue = $wp_scripts->queue;
if(!empty($in_queue))
{
$scripts = array();
foreach($in_queue as $script)
{
$src = $wp_scripts->registered[$script]->src;
$src = ( (preg_match('/^(http|https)\:\/\//', $src)) ? '' : get_bloginfo('url') ) . $src;
$scripts[] = '{' . $script . ':"' . $src . '"}';
}
echo "<script type=\"text/javascript\" src=\"".THEME_JS."head.js\"></script>\n";
echo "<script type=\"text/javascript\">head.js(\n". implode(",\n", $scripts). "\n);</script>\n";
}
$wp_scripts->queue = array();
}
It outputs something like this:
<script type="text/javascript">head.js(
{jquery:"/wp-includes/js/jquery/jquery.js"},
{jquery_lastfm:"http://localhost/lucianomammino/wp-content/plugins/lastfm-recent-tracks-widget/js/jquery.lastfm.js"},
{nav:"http://localhost/lucianomammino/wp-content/themes/lmtheme/js/jquery.dropdown.js"}
);</script>
Notice that it also uses script labeling that could be really useful sometimes to identify what (and when) scripts are loaded.
</body>and they will load after the document is rendered... – One Trick Pony Jan 24 '11 at 15:13