PHPackages                             mbrowniebytes/yii2-clean-assets - 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. mbrowniebytes/yii2-clean-assets

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

mbrowniebytes/yii2-clean-assets
===============================

Clean yii2 web/assets/ directory

0.1.0(8y ago)1108.4k↓50%3[1 issues](https://github.com/mbrowniebytes/yii2-clean-assets/issues)MITPHP

Since Sep 3Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mbrowniebytes/yii2-clean-assets)[ Packagist](https://packagist.org/packages/mbrowniebytes/yii2-clean-assets)[ RSS](/packages/mbrowniebytes-yii2-clean-assets/feed)WikiDiscussions master Synced 1mo ago

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

Yii2 command extension to clean Yii web/assets/ directory
=========================================================

[](#yii2-command-extension-to-clean-yii-webassets-directory)

While developing an app, and using Yii2 assets, as you make changes to js and css files, the web/assets/ directory will fill up with cached assets.

This extension removes old caches from Yii's web/assets/ directory

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require mbrowniebytes/yii2-clean-assets:0.1.0

```

or add

```
"mbrowniebytes/yii2-clean-assets": "0.1.0"
```

to the require section of your composer.json.

Usage
-----

[](#usage)

To use this extension, add the following code in your application configuration

- basic template: config/console.php:
- advanced template: common/config/main-local.php

```
'controllerMap' => [
    'clean-assets' => [
        'class' => 'mbrowniebytes\yii2cleanassets\CleanAssetsController',
    ],
],
```

Then call the extension from the command line

```
/path/yii/web/assets> ls -l
08/2/2017  05:07 PM              1069cc51
08/2/2017  05:07 PM              324e82f6
08/4/2017  09:29 AM              8443a260
08/4/2017  10:39 AM              a66e14a3
08/4/2017  09:28 AM              a7594ccf

/path/yii> php yii clean-assets dry-run verbose keep=2
Checking web/assets/ to remove old caches ..
would have removed web/assets/1069cc51, last modified Aug 2, 2017 05:07:21 PM
would have removed web/assets/324e82f6, last modified Aug 2, 2017 05:07:22 PM
would have removed web/assets/a7594ccf, last modified Aug 4, 2017 09:28:26 PM
Done. Removed 0 web/assets/ caches

```

Since keep=2 was supplied, the 2 newest caches would be kept.

You could also call the extension in a common event so assets are 'auto' cleaned

```
