Yii2 disable Bootstrap Js, JQuery and CSS

Yii2 disable Bootstrap Js, JQuery and CSS

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Yii2 Disable Bootstrap JS, CSS

When migrating a legacy Yii2 application to a custom design system or utilizing a UI library that doesn't rely on Bootstrap, you inevitably run into asset management conflicts. The most common friction point arises when attempting to completely strip out the framework's default assets while maintaining the necessary JavaScript for other components like yii\widgets\ActiveForm.

A frequent attempt to solve this involves modifying the assetManager configuration in your application or module bootstrap files. Many developers try setting the css array in BootstrapAsset to an empty list, as shown below:

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [],
        ],
    ],
],

This configuration successfully removes the bootstrap.css files from the output. However, it fails to remove bootstrap.js. This happens because the BootstrapAsset bundle is designed with a specific internal structure where the CSS and JS are often treated differently within the underlying asset registration logic. Specifically, simply emptying the css array does not automatically nullify the JavaScript dependencies registered by the same bundle instance.

To fully disable Bootstrap assets in Yii2, you must explicitly clear both the CSS and JavaScript arrays in the bundle configuration. The solution requires updating the configuration to target both keys:

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

By setting 'js' to an empty array alongside the existing 'css' configuration, you ensure that the asset manager does not register the jquery.min.js, bootstrap.bundle.js, or any other related scripts associated with the framework version you are using. This approach aligns with how Yii2's asset management system processes bundle definitions: each key in the configuration array maps directly to a specific file type within the bundle's manifest.

However, there is a critical pitfall to consider when making this change. If your application relies on yii\widgets\ActiveForm, you will likely encounter an error stating that the yii-bootstrap5 or yii-bootstrap4 extension cannot be loaded because it requires Bootstrap JavaScript to function correctly. The ActiveForm widget uses jQuery and Bootstrap classes for its AJAX submission handling and UI feedback (like loading spinners).

If you remove these assets but need to keep the ActiveForm widget, you have two viable paths forward:

  1. Use a Separate Asset Bundle: You can load your custom jQuery or other JS libraries manually in a separate bundle (e.g., yii\web\JqueryAsset) and ensure they are loaded before any widgets that depend on them. Note that if you are using Bootstrap 4, the ActiveForm might still expect specific global variables or methods provided by Bootstrap's JS.
  2. Switch to a Different Widget Implementation: The most robust solution for a fully custom frontend is to implement your own form validation and AJAX handling logic without relying on yii\widgets\ActiveForm. This involves manually rendering the form fields and using JavaScript (like vanilla JS or a framework like Alpine.js) to handle validation events (input, change) and submission.

It is also worth noting that if you are using Yii2 Framework 2.0.45 or later, the asset management behavior has been refined in subsequent minor versions. Always ensure your dependencies are up to date before making significant changes to asset bundling logic.

If you are maintaining a large codebase and need to document this change for other team members, it is helpful to mention that simply clearing css is insufficient for full removal of the Bootstrap dependency. The trade-off here is gaining a clean slate for your frontend design in exchange for having to manually manage the JavaScript event listeners that Bootstrap previously handled automatically. For projects where this architectural shift is necessary, ensuring your custom JS handles these interactions explicitly is the key to avoiding runtime errors.

Our network