» » » How to clear the assets cache in Yii2

How to clear the assets cache in Yii2

Follow by Email
Facebook
1 min read

With Yii2, it comes with the asset management calls asset bundleAn asset bundle is simply a collection of assets located in a directory. When you register an asset bundle in a view, it will include the CSS and JavaScript files in the bundle in the rendered Web page.

 

Below is my asset bundle setting in my application. I use the advanced template from Yii2 and I use the frontend for my application(backend, console, and frontend folders are generated from the advanced template from Yii2). The below snippet code is in the AppAsset.php you can name the file whatever to fit you need. The location is the same as namespace as Yii2 standard.

<?php

namespace frontend\assets;
use yii\web\AssetBundle;

/**
 * Main frontend application asset bundle.
 */
class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/site.css',
    ];
    public $js = [
    ];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
    ];
}
?>

I set up gulp for compiling the sass file and put the generated CSS, JS or fonts file at frontend/web/assets. The frontend/web is my root application. That means Yii will cache all CSS, fonts and js files in frontend/web/assets. Every time I run gulp to change the style or js script or fonts file, I have to delete all cache files in frontend/web/assets then refresh my browser(Ctrl+F5 for Windows) to see the changes. And that’s it.

 

Follow by Email
Facebook