Yii 1.1: optimized-client-script

Optimized Client Script Resources
3 followers

This extension will allow you to automatically combine all script files and css files into a single (or several) script or css files. Basically this will reduce the HTTP calls for resources files by merging several resources files into a single (or more) files.

Script files:

Script files are merged based on their position, If you use the 'CClientScript::POS_HEAD' you will end up with a single file for all the script files you've used on that page. If you use 'CClientScript::POS_HEAD' and 'CClientScript::POS_END' for example then you'll end up with two files for each page on that request, Since those resources are located in different positions.

Resources

Documentation

Requirements

Yii 1.1.x or above If using the googleComplier API feature then the 'googleComplier' extension needs to be installed and enabled. Download & Install.

Description:

This extension will allow you to automatically combine all script files and css files into a single (or several) script or css files. Basically this will reduce the HTTP calls for resources files by merging several resources files into a single (or more) files.

Script files:

Script files are merged based on their position, If you use the 'CClientScript::POS_HEAD' you will end up with a single file for all the script files you've used on that page. If you use 'CClientScript::POS_HEAD' and 'CClientScript::POS_END' for example then you'll end up with two files for each page on that request, Since those resources are located in different positions.

Usage:

Using this extension is as simple as adding the following code to the application configuration under the components array:

'clientScript' => array(
                        'class' => 'ext.clientScript.clientScript',
                        'combineScriptFiles' => true, // By default this is set to false, set this to true if you'd like to combine the script files
                        'combineCssFiles' => true, // By default this is set to false, set this to true if you'd like to combine the css files
                        'googleCompiler' => true, // if you have the googleCompiler extension installed then you can set this to true to compile the script code into an optimized and shorter code.
                        'googleCompilerLevel' => 'SIMPLE_OPTIMIZATIONS' // If you enable the above setting then you can specify here the compilation level that can be one of the following:
                                                                        // 'WHITESPACE_ONLY', 'SIMPLE_OPTIMIZATIONS', 'ADVANCED_OPTIMIZATIONS'
),

Then you'd use the regular 'registerScriptFile' & 'registerCssFile' methods as normal and the files will be combined.

NOTE:

This is currently in testing phase so this should not be used on a production environment.

Known Issues:

There are several private class members in the CClientScript class, So merging script blocks and codes and css blocks is impossible. Moreover when using this class css and js blocks might not work properly due to the fact that there are private class members in the class which cannot be overridden. I have filed a bug report to see if those can be set as protected instead.

Other issues may also arise when using this extension so you should test this out on a development application and environment prior using it on a production environment.

Reporting Issue:

Reporting Issues and comments are welcome. For better issue control and management please report any issue to the google project hosting that is listed in the extension overview tab.

Change Log

May 2, 2010

  • Initial release.

Total 2 comments

#2950 report it
vario at 2011/03/01 05:04am
Generates a 428kb file...

Hi,

I've installed this plugin and it appears to do something odd.

I noticed it was compiling my javascript files into a 544KB file. I took out my scripts from the registerScriptFile declarations and it generated a 428KB file with no additions. Why is this? What's being added?!

#470 report it
dongbeta at 2010/05/22 10:21pm
I like it

Try it later

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: Vince.
  • Category: Others
  • Votes: +3
  • Downloaded: 884 times
  • Created on: May 2, 2010
  • Last updated: never