labjs Using LABjs and clientScript to dynamically load javascript in the header tag which increases speed.

  1. Requirements
  2. Usage

"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(); }'
);
1 0
6 followers
283 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Developed by: aCodeSmith
Created on: Jan 25, 2013
Last updated: 11 years ago

Downloads

show all

Related Extensions