This extension allows you to seamlessly minify and merge your CSS and JS files.
Requirements ¶
Tested on 1.1.9, should work on 1.1.*
Changelog ¶
20120507.1438 UTC+1
- fixed bug where the wrong resources were checked, causing the js to rebuild every request comment#8052 crasx
- fixed bug where POS_* was ignored; thanks Renka
20120330.1039 UTC+1
- added LOCK_EX to file_put_contents() to prevent certain access issues
20120327.1112 UTC+1
- fixed bug on Windows(?) hosts; comment#7505 Jesse
- added return values to registerScript and registerCss; comment#7492 thyseus
- fixed a bug where CSS wasn't loaded correctly
Usage ¶
Extract the files to the corresponding directories, components/ into compontents/ and extensions/ into extensions/ then configure the config file as described below, now MinifyClientScript will do the rest. :) Please comment if you have comments/suggestions/questions.
Example main.php:
return array(
...
'components'=>array(
...
'clientScript'=>array(
'class'=>'application.components.MinifyClientScript',
),
...
),
...
);
More on this extension ¶
I have written a blog about minifying and merging CSS/JS, read more about it HERE.
Very slow
This extension is VERY slow with twitter bootstrap.
Page loaded without extension:
ab -c10 -n500 http://localhost/index.php
Requests per second: 15.56 [#/sec] (mean)
Page loaded with extension:
Requests per second: 0.76 [#/sec] (mean)
RE: Very slow
Koduc, did you make sure to run this test in production mode? and did you also build the cache beforehand?
Optimization
I noticed that whenever the content of the compiled JavaScript is empty, there is still a script tag generated, causing an unnecessary http request.
check for file isn't empty
on lines 146,198 and 202
also need ckeck on file size if equal zero byte,ignore publish those files
if(filesize($this->minifyPath . "/$filenames[$media]") > 0){ $this->registerLinkTag("stylesheet", "text/css", Yii::app()->assetManager->getPublishedUrl($this->minifyPath) . "/$filenames[$media]", $media == "default" ? null : $media); } . . . if ($position===self::POS_HEAD){ if(filesize($this->minifyPath . DIRECTORY_SEPARATOR . "$filenameCore.js") > 0) $this->registerScriptFile($publishedMinifyPath . "/$filenameCore.js", $position); } if(filesize($this->minifyPath . DIRECTORY_SEPARATOR . "$filename.js") > 0) { $this->registerScriptFile($publishedMinifyPath . "/$filename.js", $position); }
Slow?
I think its slowing down my site. Without this < 1 sec after this 8 sec.
Thanks,
Shiv
Parameter Question
I have simply followed that setup description here and the minification works but the most of the JS code is missing so my app doesn't run well anymore. Beside the embedded coded that has been minified and rendered I have several files in header like
$cs ->registerScriptFile($baseUrl.'/js/json2.js')
Those are all missing and may have been replaced by 2 new generated JS file like this:
But definately is is just a little piece of my JS code inside...
Are there any parameters I could play around and try to fix it?
Maybe you have an idea what goes wrong..?
Btw, the minification could be improved by shortening also variables inside functions e.g. function(response){if(response!='') minified: function(e){if(e!='')
issue homeUrl - baseUrl
Hi
In my case the extension does not work (I use Yii ver 1.1.15)
I replace Yii::app()->homeUrl with Yii::app()->baseUrl in MinifyClientScript.php and it works!
Generate in each request
The extension seems to regenerate css and js in every request.
Is there way to improve it ?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.