Yii 1.1: ac-clientscript-minify

This extension allows you to combine, minify, compress and cache your CSS and JS files.
6 followers

This extension allows you to group files to be combined.

By default CSS files are grouped by "media" value ('' [default], 'all', 'screen', 'print', etc...)

By default JS files are grouped by "position" value (self::POS_HEAD [default], self::POS_END, etc...)

Requirements

Tested with Yii 1.1.10 (but I see no reason why it would not work for previous Yii versions)

Usage

Extract into protected/extensions directory

Edit your config file:

...
'controllerMap'=>array(
    'min'=>'ext.ExtACClientScriptMinify.controllers.ExtACClientScriptMinifyController',
),
...
'components'=>array(
    ...
    'clientScript' => array(
        'class'=>'ext.ExtACClientScriptMinify.components.ExtACClientScriptMinify',
        'controller'=>'min', // the same value set in controllerMap
        'debug' => false, // optional: default false
        'cache' => 'off', // optional: default 'off' Others values 'file', 'apc', 'memcache'
        'cachePath' => '', // for file caching; optional: default '' (Yii::app() -> runtimePath.'/minify_cache'),
        'maxAge' => 60*60*24*30, //optional: default 1800 (Cache-Control: max-age value sent to browser (in seconds))
    ),
    ...
),

Examples

Simple way: Add files into default group

For CSS

Yii::app()->clientScript->registerCSSFile(Yii::app()->request->baseUrl.'/css/style1.css');
Yii::app()->clientScript->registerCSSFile(Yii::app()->request->baseUrl.'/css/style2.css');

For JS

Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/script1.js');
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/script2.js');

More groups: Add files into default group and secondary group For CSS

Yii::app()->clientScript->registerCSSFile(Yii::app()->request->baseUrl.'/css/style1.css', 'screen');
Yii::app()->clientScript->registerCSSFile(Yii::app()->request->baseUrl.'/css/style2.css', 'screen');
Yii::app()->clientScript->registerCSSFile(Yii::app()->request->baseUrl.'/css/style3.css', 'screen', 'secondary');
Yii::app()->clientScript->registerCSSFile(Yii::app()->request->baseUrl.'/css/style4.css', 'screen', 'secondary');

Will create two files (style1.css+style2.css and style3.css+style4.css)

For JS

Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/script1.js', self::POS_HEAD);
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/script2.js', self::POS_HEAD);
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/script3.js', self::POS_HEAD, 'secondary');
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/script4.js', self::POS_HEAD, 'secondary');

Will create two files (script2.css+script3.css and script3.css+script4.css)

Total 13 comments

#12499 report it
Ayrton2001 at 2013/03/24 07:16am
Re: route?

this

'min / <action:(.*)>' => 'min / default',

is not necessary because it is the controllerMap that handles this

'controllerMap'=>array(
    'min'=>'ext.ExtACClientScriptMinify.controllers.ExtACClientScriptMinifyController',
),

the rules in the htaccess file is required only if UrlManager has

'urlFormat' => 'path',
#12496 report it
crasx at 2013/03/23 10:57pm
route?

What should the route be for this? I tried

'min/<g:(.*)>'=>'min/default',

but it didn't work. Also you may want to update your documentation, you keep talking about adding min.php to htaccess but you don't provide such file with the release

edit: figured it out. route should be

'min/<group:(.*)>'=>'min/default',
#12477 report it
Ayrton2001 at 2013/03/22 11:25am
Re: hmm only on Windows

The problem is always Windows ;)

#12476 report it
Ayrton2001 at 2013/03/22 11:23am
Re: minify file

This weekend I'll create a project with Yii Boilerplate and check on the problem

#12474 report it
DrMabuse at 2013/03/22 11:16am
hmm only on Windows

http://4you-free.com/login on my debian it works correctly

Thx for spend Time

#12473 report it
DrMabuse at 2013/03/22 11:10am
Sorry

in my minifygroups.var

a:2:{s:36:"2528a03137dca73230d2de0b77681736.css";a:5:{i:0;s:115:"F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild/backend/www/assets/9126dddd/css/bootstrap.min.css";

in my .htaccess

Options +FollowSymLinks -Multiviews
IndexIgnore /
RewriteEngine on
RedirectMatch 404 /\\.git(/|$)
RewriteRule ^white_rabbit_guild/backend/www/min/(.*)$ min.php [L,NC]
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
 
RewriteRule . index.php

But when i locked in my Network

i have type text/html and the path are wrong F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild

i delete the minfygroups.var and it would be generae a new with the same path

#12471 report it
Ayrton2001 at 2013/03/22 10:57am
Re: minify file

Try this htaccess rule:

RewriteRule ^white_rabbit_guild/backend/www/min/(.*)$ min.php [L,NC]

in every way depends on your configuration

#12469 report it
DrMabuse at 2013/03/22 10:37am
Url ?

http://localhost/white_rabbit_guild/backend/www/min/2528a03137dca73230d2de0b77681736.css

2528a03137dca73230d2de0b77681736.css
/white_rabbit_guild/backend/www/min
GET
(canceled)
text/html
login:5
Parser
429B
0B
1.58s
1.57s
1.57s7ms
39691a1f04fb720449d96d6cc94dcf73.js
/white_rabbit_guild/backend/www/min
GET
(canceled)
text/html
login:6
Parser
429B
0B
1.59s
1.59s
1.59s3ms
#12468 report it
Ayrton2001 at 2013/03/22 10:30am
Re: minify file

the js file in the html code generated, what gives (via web)?

#12466 report it
DrMabuse at 2013/03/22 10:19am
minify file
a:2:{s:36:"2528a03137dca73230d2de0b77681736.css";a:5:{i:0;s:115:"F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild/backend/www/assets/9126dddd/css/bootstrap.min.css";i:1;s:115:"F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild/backend/www/assets/9126dddd/css/bootstrap-yii.css";i:2;s:121:"F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild/backend/www/assets/9126dddd/css/jquery-ui-bootstrap.css";i:3;s:123:"F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild/backend/www/themes/bootstrap/css/bootstrap-responsive.css";i:4;s:119:"F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild/backend/www/themes/bootstrap/css/font-awesome.min.css";}s:35:"22f84a60a89ce559ce4e093264ee5346.js";a:4:{s:6:"jquery";s:103:"F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild/backend/www/assets/3d9764b6/jquery.js";s:75:"/white_rabbit_guild/backend/www/assets/9126dddd/js/bootstrap.bootbox.min.js";s:121:"F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild/backend/www/assets/9126dddd/js/bootstrap.bootbox.min.js";s:63:"/white_rabbit_guild/backend/www/assets/9126dddd/js/bootstrap.js";s:109:"F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild/backend/www/assets/9126dddd/js/bootstrap.js";s:13:"yiiactiveform";s:117:"F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild/backend/www/assets/3d9764b6/jquery.yiiactiveform.js";}}

oh i see F:\xampp\htdocs\white_rabbit_guild\backend\www/white_rabbit_guild/backend/www/assets/9126dddd/js/bootstrap.bootbox.min.js are wrong path it have to F:\xampp\htdocs\white_rabbit_guild\backend\www/assets/9126dddd/js/bootstrap.bootbox.min.js

#12463 report it
Ayrton2001 at 2013/03/22 10:11am
Re: Sorry doesn`t work

JS/CSS files are not written but created on the fly through the file minifyGroups.var. What's in it?

#12458 report it
DrMabuse at 2013/03/22 05:48am
Sorry doesn`t work

Hello thx for your quick answer but doesnt help me.

Here is my config iam using Yii Boilerplate . The extensions is here my .htaccess i test it with uncomment all others stuff in my .htaccess but there it doesn`t help. Where is the line did you write the files ? i have the minifyGroups.var in my backend/runtime the min folder is in backend/www but no files . Maybe you can help that was great!! Thx

#12439 report it
DrMabuse at 2013/03/20 06:05pm
Issues

Hi i see in my network files like http://localhost/white_rabbit_guild/backend/www/min/3260db7280b3bc2f646d1b98dfa42e79.js

but the file isnt there

my conf :

'clientScript' => array(
                'class'=>'common.extensions.compressor.components.ExtACClientScriptMinify',
                'controller'=>'min', // the same value set in controllerMap
                'debug' => true, // optional: default false
                'cache' => 'file', // optional: default 'off' Others values 'file', 'apc', 'memcache'
                'cachePath' => '', // for file caching; optional: default '' (Yii::app() -> runtimePath.'/minify_cache'),
                'maxAge' => 60*60*24*30, //optional: default 1800 (Cache-Control: max-age value sent to browser (in seconds))
            ),

Leave a comment

Please to leave your comment.

Create extension