[Extension] EClientScript

(Hightman) #1

Extension download:



I have found another extension created by Vince, but it is too complex and there are many bugs during my usage.


This extension just extend from {link: CClientScript} using few codes, it 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. It can automatically detect the required list of files, and generate a unique filename hash, so boldly ease of use.

Css Files:

CSS files are merged based on there media attribute, background images with a relative path in file can also be displayed correctly.

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.

(L Nagash) #2

Hi! I try use in my project ECLientScript and got:

Fatal error: Maximum execution time of 60 seconds exceeded in D:\usr\…\protected\extensions\EClientScript\EClientScript.php on line 314

Yii version 1.4

all js & css files placed in js/ css/ directories

(Hightman) #3

Try to turn off ‘optimizeScriptFile’, set this options to false.

because the optimization is called via google compiler.

(Mail) #4

Fatal error: Maximum execution time of 300 seconds exceeded in \www\protected\extensions\minify\EClientScript.php on line 316

(combineCssFiles=true, all other options=false)

(Dragos) #5

I also wanted a gzip version of this, so here is my modification.

add the public var to the class


 * @var boolean if a gzip version of the files should be created


public $gzip = false;

create a new private method


 * GZIP a file


 * @param $path The file to gzip

 * @return boolean


private function gzipFile($path) {

	$zp = gzopen($path.'.gz', "w6");

	if ($zp) {

		gzwrite($zp, file_get_contents($path));

		return gzclose($zp);

	} else {

		return false;




if ($this->gzip) {



in combineCssFiles() and combineScriptFiles() after the line with:

file_put_contents($fpath, $fileBuffer);

now in your config file you can add

‘gzip’ => true / false to enable/disable the gzip

Great extension hightman ^_^

(Xexys) #6

Hi!! Thank you for your great extension.

I try it and it works perfect! But then I use it with optimizeScriptFiles I have some errors in my output javascript files. I tried to use JSMin instead JSMinPlus and in works without errors. Maybe you can change your code or make optimizeScriptFiles to be protected.

Thank you!!

(Vedurupakamahesh) #7

Hey This is worked for me,

changed in



// application components

‘clientScript’ => array(

	  'class' => 'ext.ExtendedClientScript.ExtendedClientScript',

	  'combineCss' => true,

	  'compressCss' => false,

	  'combineJs' => false,

	  'compressJs' => false,


//(combineCssFiles=true, all other options=false)

thank you…

(Hightman) #8

Mar 29, 2013

  • New version number 1.5

  • Compatiable with the 3rd parameter of registerScript and registerScriptFile

  • Add support for conditional loading js/css file in IE.

  • Prepend the base url of current request when register a script/css file with relative path

Mar 27, 2013 (by Muayyad Alsadi)

  • New version number 1.4

  • update JSMinPlus, CssMin

  • use stronger hash for file names

  • consider modification time for calculating hash

  • enable all features by default

Dec 06, 2010

  • Fixed problem for css files that begin with @charset "xxx", it should be in the first line of file and not repeatly.

  • Add support for theme resource files.

(Hightman) #9

$cs = Yii::app()->clientScript;


// result to: <--[if lt IE 9]><script src="/js/html5.js"></script><![endif]-->

$cs->registerScriptFile('/js/html5.js', CClientScript::POS_HEAD, array('media' => 'lt IE 9'));

// result to: <!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="bootstrap/css/ie.css" /><![endif]-->

$cs->registerCssFile('/css/ie.css', 'lte IE 6');

(Alsadi) #10

hi, hightman

how can we collaborate on this. I have more suggestions and enhancements

I use github

and I already took pull requests from other people (like Alexey xt99)

(Alsadi) #11

I’ve merged your pull request thank you very much

I shall push any modifications to your repo