renderAjax REloads Css files

I am trying to renderAjax a subform that has the kartik switchinput.

The result of the renderAjax is the html and that includes the css files that the switch needs.

However those css files were already loaded on top of the page, and now it overrides my custom css

How can I prevent the renderAjax to reload the switchinput files ?

Any advice

deregister the switch input asset bundle before you renderAjax


unset(Yii::$app->assetManager->bundles['kartik\swtichinput']);

Thank you SOOO much for your answer… this problem is bugging me like crazy.

However it is not working…

I have a simple view that renders a subview with ajax



print_r(Yii::$app->assetManager->bundles);


unset(Yii::$app->assetManager->bundles['kartik\swtichinput']);


unset(Yii::$app->assetManager->bundles['yii\grid\GridViewAsset']);


echo "<HR>";


print_r(Yii::$app->assetManager->bundles);





echo $this->renderAjax('setting_tab/_preview_form', ['model' => $model,]);


my header loads



...


<link href="/assets/ee0a686c/compiled/css/basics_medium.css" rel="stylesheet" media="screen and (max-width: 640px)">


<link href="/assets/ee0a686c/compiled/css/basics_wide.css" rel="stylesheet" media="screen and (min-width: 1024px)">


<link href="/assets/4445b25b/css/bootstrap-switch.css" rel="stylesheet">


<link href="/assets/4445b25b/css/bootstrap-switch-kv.css" rel="stylesheet">


<link href="/assets/36c7789d/css/kv-widgets.css" rel="stylesheet">


<link href="/assets/ee0a686c/css/i18n.css" rel="stylesheet">


//


the ajax still starts rendering with



<link href="/assets/676e3db8/css/bootstrap.css" rel="stylesheet">


<link href="/assets/4445b25b/css/bootstrap-switch.css" rel="stylesheet">


<link href="/assets/4445b25b/css/bootstrap-switch-kv.css" rel="stylesheet">


<link href="/assets/36c7789d/css/kv-widgets.css" rel="stylesheet">


at the end of the ajax is also loads the JS which are also loaded at the end of the parent view



<script src="/assets/b383786d/jquery.js"></script>


<script src="/assets/4445b25b/js/bootstrap-switch.js"></script>


<script src="/assets/36c7789d/js/kv-widgets.js"></script>


<script src="/assets/558e33a0/yii.js"></script>


<script src="/assets/558e33a0/yii.validation.js"></script>


<script src="/assets/558e33a0/yii.activeForm.js"></script>


Any suggestions ?

When I remove the switchinput from the view

Then the renderAjax no longer loads the css again (which is good…)

… but I kinda like that switch input…

When I do a normal render

then teh additional CSS and JS are not loaded…

but as this view is part of the tab-x it needs to be rendered with Ajax to show the most recent db values