PHPackages                             jalle19/yii-yui-clientscript - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jalle19/yii-yui-clientscript

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jalle19/yii-yui-clientscript
============================

The end-all, be-all minifying client script implementation for Yii

1.0.2(11y ago)15.1kBSD-2-ClausePHPPHP &gt;=5.3.0

Since Oct 31Pushed 11y ago2 watchersCompare

[ Source](https://github.com/Jalle19/yii-yui-clientscript)[ Packagist](https://packagist.org/packages/jalle19/yii-yui-clientscript)[ Docs](https://github.com/Jalle19/yii-yui-clientscript)[ RSS](/packages/jalle19-yii-yui-clientscript/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

yii-yui-clientscript
====================

[](#yii-yui-clientscript)

The end-all, be-all minifying client script implementation for Yii. It is able to combine your CSS and script files as well as minimize them using the YUI compressor (available via the [php-yui-compressor](https://github.com/Jalle19/php-yui-compressor) package).

Features
--------

[](#features)

- drop-in replacement for the standard CClientScript (no changes to the way you register scripts and stylesheets)
- uses the native Java-based YUI compressor instead of one of the countless more-or-less unmaintained ports of it
- detects global strict mode in JavaScript files and combines such scripts separately from standard scripts
- extracts `@import url("");` (e.g. Google Font imports) statements and prepends them in the combined output to ensure they work correctly
- uses unique filenames for the combined files, meaning you won't have to manually implement cache-busting
- compresses inline scripts too

Installation
------------

[](#installation)

Use Composer to install, then add the following to your application configuration:

```
// change this path if necessary
Yii::setPathOfAlias('yiiyuiclientscript', realpath(__DIR__.'/../../vendor/jalle19/yii-yui-clientscript/src/yiiyuiclientscript'));
...
return array(
	...
	'components'=>array(
		...
		'clientScript'=>array(
			'class'=>'yiiyuiclientscript\components\ClientScript',
		),
		...
	),
	...
),
```

You'll also need to include the Composer autoloader in your bootstrap script. Usually this can be done using `require_once('vendor/autoload.php');`.

Configuration
-------------

[](#configuration)

See the documentation for [php-yui-compressor](https://github.com/Jalle19/php-yui-compressor) for which options are available for the YUI compressor. The options are specified by "compressorOptions" in the component configuration, e.g.:

```
...
return array(
	...
	'components'=>array(
			...
			'clientScript'=>array(
				'class'=>'yiiyuiclientscript\components\ClientScript',
				'compressorOptions'=>array(
					'line-break'=>80,
					'disable-optimizations'=>true,
				)
			),
			...
	),
	...
),
```

### Excluding files

[](#excluding-files)

Sometimes you may want to combine and compress all files but one (perhaps because it changes too often causing all scripts to need re-combination). You can specify a pattern that matches these files using the "exclude" option:

```
...
return array(
	...
	'components'=>array(
			...
			'clientScript'=>array(
				'class'=>'yiiyuiclientscript\components\ClientScript',
				'exclude'=>array(
					'MainMenu'
				),
			),
			...
	),
	...
),
```

The pattern matching is done using `strpos()` on the script URL, meaning in the example above the script `MainMenu-typeahead-1.js` (and naturally all other scripts having "MainMenu" in their name) would be registered separately.

### Using a custom file resolver

[](#using-a-custom-file-resolver)

A registered script URL must be converted internally to the absolute path to the file in question. Depending on your project layout the default implementation may not do the trick. In that case you'll need to define your own path resolver:

```
...
return array(
	...
	'components'=>array(
			...
			'clientScript'=>array(
				'class'=>'yiiyuiclientscript\components\ClientScript',
				'pathResolver'=>'\MyPathResolver'
			),
			...
	),
	...
),
```

Example implementation (see the interface for more details):

```
