Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 How to add parameters to script tag

The JS assests that gets renders looks like this:

<script src="/assets/a00ccd3f/jquery.min.js"></script>

I need to add the async="async" tag to it.

so it should look like

<script src="/assets/a00ccd3f/jquery.min.js" async="async" ></script>

How can i do this?

like image 763
Chinmay Waghmare Avatar asked May 14 '15 13:05

Chinmay Waghmare


1 Answers

In your own AssetBundle you can add

public $jsOptions = [
    'async' => 'async',
];

If you want to add this to the Yii2 JqueryAsset bundle (or some other bundle) you can add it to the components parts of your config:

'assetManager' => [
    'bundles' => [
        'yii\web\JqueryAsset' => [
            'jsOptions' => [
                'async' => 'async'
            ],
        ],
    ],
],
like image 66
Jap Mul Avatar answered Sep 22 '22 18:09

Jap Mul