ac-clientscript-minify This extension allows you to combine, minify, compress and cache your CSS and JS files.

  1. Requirements
  2. Usage
  3. Examples

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)

3 0
7 followers
1 390 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Caching
Developed by: Ayrton2001
Created on: Mar 3, 2013
Last updated: 11 years ago

Downloads

show all

Related Extensions