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)
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)) ),
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
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?
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
Re: minify file
the js file in the html code generated, what gives (via web)?
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 429 B 0 B 1.58 s 1.57 s 1.57 s7 ms 39691a1f04fb720449d96d6cc94dcf73.js /white_rabbit_guild/backend/www/min GET (canceled) text/html login:6 Parser 429 B 0 B 1.59 s 1.59 s 1.59 s3 ms
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
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
hmm only on Windows
http://4you-free.com/login on my debian it works correctly
Thx for spend Time
Re: minify file
This weekend I'll create a project with Yii Boilerplate and check on the problem
Re: hmm only on Windows
The problem is always Windows ;)
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',
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',
Not working in Nginx
This extension is not working in nginx. But working in apache
I have added the below config in main.php
'clientScript' => array( 'class'=>'ext.ExtACClientScriptMinify.components.ExtACClientScriptMinify', 'controller'=>'min', // the same value set in controllerMap 'debug' => false, // 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))
I am getting 404 Not found Error in browser.
Can you please help me to solve this issue in nginx.
My nginx config
location / { try_files $uri $uri/ /index.php$args; include /etc/nginx/mime.types; } location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ { expires 30d; log_not_found off; } location ~ \.php$ { try_files $uri =404; include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/php-fpm/www.sock; fastcgi_buffer_size 64K; fastcgi_buffers 128 8k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_read_timeout 600; } gzip on; gzip_comp_level 6; gzip_vary on; gzip_types text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/rss+xml text/javascript image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype image/png image/gif image/jpeg image/jpg; } }
Also i tried with below config's
location /css { rewrite ^/css/(.*\.css) /min/index.php?f=css/$1 last; } location /min { rewrite ^/min/([a-z]=.*) /min/index.php?$1 last; } location /js { rewrite ^/js/(.*\.js) /min/index.php?f=js/$1 last; }
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.