Attempting to use HeadJS in Joomla. I added a code to my template - it grabs the javascript files within the mind output, prepares a string to output them between mind.js code, then removes all javascript files from joomla's mind output tag.

However , some scripts are loaded following the template. For instance, a module will enqueue some script files following the template has loaded, so its files appear outdoors of my mind.js code. Any ideas the way i can control this?

$data = $this->getHeadData();

if( $data['scripts'] ){
    foreach ($data['scripts'] as $url=>$type){
        if( !strstr($url, 'ajax.googleapis.com/ajax/libs/jquery') )
        $headjs[] = $url;
    }
    unset( $data['scripts'] );
    $data['scripts'][$template . '/js/head.js'] = array(
        'mime' => 'text/javascript',
        'defer' => false,
        'async' => false);
    $this->setHeadData($data);
}

After which...

 <script>
        head.js(
        <? foreach($headjs as $script): ?>
            '<?=$script?>',
        <? endforeach; ?>
            function(){
            }
        );
    </script>

Different extensions can hook up with different occasions which are triggered throughout processing the output (so despite template is made).

Smartest choice I discovered to date is creating system wordpress plugin and moving it's to be all of the available system plug ins.

Now you must two options:

  1. use onBeforeCompileHead event (I suppose introduced Joomla 1.5.23) to maneuver scripts to headjs.
  2. use onAfterRender event and parse mind web coding therefore it is loaded using headjs.

This really is fine should you adjust async scripts loading in which you have complete control within the website, but it is nearly impossible to implement as universal extension for Joomla. Some extensions use inline scripts in mind, some within the the html body and you'd need to preserve order of execution (simple example: Mootools need to load first).

I personally use to load asynchronously only individuals scripts which I have incorporated myself (during my template or my extension). Any scripts which are added with Joomla core (Mootools, core.js, etc.) or any other extensions I do not touch.