I\'m writing my first Yii2 application and I want to disable the assets caching, while I\'m developing.
Can I disable the caching using the ./config/ .php files?
1) Globally it's possible with help of AssetMananer. There is special option $forceCopy for this.
You can set it like this with component:
use Yii;
Yii::$app->assetManager->forceCopy = true;
Or in application config:
'components' => [
'assetManager' => [
'class' => 'yii\web\AssetManager',
'forceCopy' => true,
],
],
2) If you want disable caching in specific AssetBundle, use $publishOptions property:
public $sourcePath = '...' // In order to use $publishOptions you should specify correct source path.
public $publishOptions = [
'forceCopy' => true,
];
Alternatively you can specify this like in option 1 with help of bundles property. For example:
'components' => [
'assetManager' => [
'class' => 'yii\web\AssetManager',
'forceCopy' => true,
'bundles' => [
'yii\bootstrap\BootstrapAsset' => [
'forceCopy' => true,
],
],
],
],
But this:
'forceCopy' => YII_DEBUG,
is more flexible, because it disables this asset bundle caching only in debug mode, but allows on production server. YII_DEBUG
is set in web/index.php
.