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.
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',
];
}
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'=>[]
],
],
],
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'=>[]
],
],
],
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' => [],
],
],
],
Thank you all, I hope that my article helped you in some way.