"LABjs (Loading And Blocking JavaScript) is an open-source (MIT license) project supported by Getify Solutions. The core purpose of LABjs is to be an all-purpose, on-demand JavaScript loader, capable of loading any JavaScript resource, from any location, into any page, at any time. Loading your scripts with LABjs reduces resource blocking during page-load, which is an easy and effective way to optimize your site's performance." http://labjs.com/
Currently in beta mode!
The method registerScriptList() will load the list of js files using the LABjs $LAB method. Which ends up making your script load parallel to page assets will help the overall page load faster.
Requirements ¶
Yii 1.1 or above
Usage ¶
'components'=>array(...
...
'labScript' => array(
'class' => 'application.extensions.lab.labScript'
),
Load jQuery
$labScript = Yii::app()->labScript;
$labScript->registerScriptList(array('/js/jquery.js'), 'function(){ alert("jquery loaded"); }');
Load three scripts with a callback for the first file.
$labScript = Yii::app()->labScript;
$labScript->registerScriptList(
array(
'/js/form.js'=>'function(){ form.init(); }',
'/js/example.js',
'/js/print.js'
),
'function(){ alert("end of chain") }'
);
Don't bind events to document.ready! ~~~ [javascript] $(document).ready(function(){
//This will not work!
example.init();
}); ~~~
Add your would be document ready code to an init function. ~~~ [javascript] var mySite = {
init: function(){
example.init();
}
} ~~~
$labScript->registerScriptList(
array(
'http//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js',
'/js/example.js',
),
'function(){ mySite.init(); }'
);
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.