This extension extends CClientScripts by utilizing Minify to minify JavaScript and CSS stylesheets for views.
//URL management
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'minify/<group:[^\/]+>'=>'minify/index',
),
),
//Customized CClientScript with Minify
'clientScript'=>array(
'class'=>'application.extensions.CClientScriptMinify',
'minifyController'=>'/minify',
),
Use to following methods to register css or js files to be minified.
Yii::app()->clientScript->registerCSSFile($url, $media); Yii::app()->clientScript->registerScriptFile($url);
Please note, the $url needs to be absolute path from your document root (where the index.php script is), i.e. '/css/main.css', '/js/myscript.js' etc.
For more Minify tweaks please check out Minify Google Code Page
Total 7 comments
Works great for me in 1.1.8 and saved me lots of time!
It is not work me in yii 1.1.5, illegal character [Прерывать на этой ошибке]
it is not work on yii 1.16
follow your tutorial, but the js and css file can't be fined?
great
Hi Jonah, thanks for your, we'd like to extend CClientScript, however as YiIFramework stands now 1.0.3 most the variables are private in CClientScript, I believe when 1.0.4 releases, the situation will be different, then we'll update this extension to extend CClientScript rather than a dirty hack.
This is not good if CClientScript is updated in the core. Instead of copying all the code of CClientScript and duplicating it in CClientScriptMinify, perhaps CClientScriptMinify should just extend CClientScript. In that case, I may very well use this.
Leave a comment
Please login to leave your comment.