简体   繁体   中英

Yii2 AssetBundle Static path

I want to include the path of css/js files in service-worker for caching. what I see Yii deployes css/js files to a dynamic directory using hash in AppAssets.

for example

/assets/a7fd2538/css/site.css

so is there a way I can disable this hashed directory a7fd2538 . and I get just

/assets/css/site.css

Thanks.

You can put your asset files directly to some accessible directory. For example in web/css/ and web/js/ . Then you will set your AppAssets bundle to use them directly without copying by specifing $basePath and $baseUrl and leaving $sourcePath empty.

For example:

namespace app\assets;

use yii\web\AssetBundle;
class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/site.css',
    ];
    public $js = [
        'js/site.js',
    ];
    // ... other definitions
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM