Can't load AssetBundle with renderAjax (Pjax)


I work on my first project on Yii2 and I’m a bit stuck.

I’m trying to use Pjax to load several page segments (stream, profile-data, photos, friends…) for a User profile page on my website.

This works fine for some segments but some of them register Js files using the yii\web\AssetBundle class and they don’t register with Pjax reload.

I think this is normal since Pjax only reloads a page segment and AssetBundle registers the Js files in 3 different positions ([POS_HEAD],[POS_BEGIN],[POS_END]) which are out of the reloaded segment.

My question is : How can I make this work?

I have some "bad" ideas in my opinion :

  1. Maybe there is a way to add a custom position which would be inside the page segment reloaded with Pjax but that would mean modify Yii2 files.

  2. Register the Js inline but this would be so ugly.

I guess there is a soft way to do this.

Thank you !


I found a good way to deal with this problem, even if there might be a better solution. I give the answer and hope it will help someone.

I created a AppAsset class which includes all of the tiny AssetBundle of every single page segment.

class AppAsset extends AssetBundle



    public $depends = [