How to disable Bootstrap and jQuery in Yii2

How to disable Bootstrap and jQuery in Yii2

Colleagues hello to all.

In today's article, we'll talk about how you can disable the default built-in Jquery and Bootstrap libraries in Yii2. In Yii2, by default, after installing the framework, the Jquery  library, together with Bootstrap, is already installed. It often happens that in a newly installed yii2 framework, the Jquery and Bootstrap libraries come in older versions, and you want to use the latest versions of the libraries.

 

yii2 disable jquery and Bootstrap

The image shows which libraries are shipped with the Yii2 framework by default.


 

The very first thing to do is comment out the  yii\web\YiiAsset and yii\bootstrap4\BootstrapAsset lines in the AppAsset.php file in the depends.public property.

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

class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/site.css',
    ];
    public $js = [
    ];
    public $depends = [
        //'yii\web\YiiAsset',
        //'yii\bootstrap4\BootstrapAsset',
    ];
}

yii2 disable jquery and Bootstrap


 

In the first option, we will simply disable Jquery itself, and leave Bootstrap. In order for us to do this, we need to add the  components array to the web.php configuration file:

'assetManager' => [
    'bundles' => [
        'yii\web\JqueryAsset' => [
            'js'=>[]
        ],
    ],
],

yii2 disable jquery and Bootstrap

After reloading the page, Jquery will not be connected to the site.


 

In the next option, we will disable Bootstrap and leave Jquery. In order for us to do this, we need to add the components array to the web.php configuration file:

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapPluginAsset' => [
            'js'=>[]
        ],
    ],
],

yii2 disable jquery and Bootstrap


 

In the very last option, we will disable everything, Bootstrap and Jquery. In order for us to do this, we need to add the  components array to the web.php configuration file:

'assetManager' => [
    'bundles' => [
        'yii\web\JqueryAsset' => [
            'js'=>[]
        ],
        'yii\bootstrap\BootstrapPluginAsset' => [
            'js'=>[]
        ],
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [],
        ],
    ],
],

yii2 disable jquery and Bootstrap


 

Thank you all, I hope that my article helped you in some way.

SIMILAR ARTICLES

jQuery - Image gallery with zoom on hover
jQuery - Image gallery with zoom on hover
WEB
Read more
Zoom blowup.js - Zoom blowup plugin with magnifying glass
Zoom blowup.js - Zoom blowup plugin with magnifying glass
WEB
Read more
jQuery Zoom - Image magnifier glass effect
jQuery Zoom - Image magnifier glass effect
WEB
Read more