9

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?

Chinmay Waghmare
  • 5,368
  • 2
  • 43
  • 68

2 Answers2

18

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'
            ],
        ],
    ],
],
Jap Mul
  • 17,398
  • 5
  • 55
  • 66
0

like this

<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace frontend\assets;
use yii\web\AssetBundle;
class ThemeCustomAsset extends AssetBundle
{
public $basePath    = '@webroot';
public $baseUrl     = '@web';
public $css = [];
public $js = [
    "js/lazysizes.min.js"
];
public $depends = [
    #'yii\web\YiiAsset',
    #'yii\bootstrap\BootstrapAsset',
];
public $jsOptions = ['async' => 'async'];
}
sylvain
  • 101
  • 1
  • 2