Support » Plugin: HeadJS Loader » [Plugin: HeadJS Loader] Scripts don't execute in order

  • A syntax error in HeadJS’ Loader will indeed cause the scripts to load in parallel, but they will not execute in order as per HeadJS’ design. This can lead to, for example, a script loading before jQuery does and all hell breaking loose. This might be browser dependent (I didn’t test), but I was able to fix it by modifying the script to use HeadJS’ syntax, like so:

    if (!empty($script_array)) {
    		$script_array = array_unique($script_array);
    		foreach ($script_array as $script_location) {
    			/* Load the scripts into a .js */
    			if ($i != 0) { $js_files .= "\n    "; }
    			$js_files .= '"' . $script_location . '"';
    			if ($i + 1 != count($script_array)) { $js_files .= ","; }
    		$headJS .= "\n<script>\nhead.js(" . $js_files . ");\n</script>";

    This may also be a side effect of me upgrading to the latest HeadJS (0.9). But that needs to be done at some point, also. XD

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thanks for that. Unfortunately, I’ve still got a problem whereby this plugin is loading things in the wrong order.

    For example:


    but swfobject needs to come BEFORE jquery, otherwise the audioplayer plugin ( doesn’t fire correctly. Or perhaps it’s not wrapping it in head.ready? It’s all a bit of a dark art!

    Not sure how I can “force” the plugin to load the scripts in the right order.

    I changed the plugins code. I changed

    $buffer = str_replace('</head>', $headJS . "\n</head>", $buffer);


    $buffer = str_replace('</title>', "</title>\n" . $headJS, $buffer);

    You also need to wrap the JavaScript code that’s inside your head tag like this,

    head.ready(function() {
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: HeadJS Loader] Scripts don't execute in order’ is closed to new replies.