Publish AssetManager files to CDN

Is there any good solution or existing extension for an Yii AssetManager which stores the files on a CDN storage like S3?

Motivation behind:

Our main problem is, that we have multiple webservers scaled horizontally, managed by K8s. Therefore Assets should be uploaded once and served as CDN url afterwards. It would be nice to have a solution on the build process of the application, but i think this won’t work due to the fact we don’t know all the assets which are used. Therefore i would develop an AssetManager which uploads the files to a CDN, stores this information in the cache (file x is uploaded) and just serve the URL in future.

I could not find any good extension or any good class which extends the AssetManager. The AssetManager does not have an interface which lets me know how to create my own AssetManager (

Any help or tipp regarding my AssetManager problem would be nice. If i can manage to get my task done, i will publish the library as oss of course.


I’ve posted an article in Russian with some examples. May be read via Google translate:

Thanks, that gave me some very good idea of how to build such a system.

There are still some issue, for instance there is a check for whether the base path is writable or not ( but this should be either done in the init() or configurable, because its not needed when working with a s3 storage (for instance).

Would you accept a PR which moves this part into the initializer? As its checking the same path over and over again for every publish action, might even increase performance due to less disc read.

Yes, I think that would be a good change.

Hi @samdark mikk150/yii2-asset-manager-flysystem uploads the assets to s3 right?

Not sure what i’m missing here, It reads from s3 correctly, but i had to upload my assets manually to s3. Here is my settings

'assetManager' =>  [
            'class'    => \white43\CloudAssetManager\CloudAssetManager::class,
            'basePath' => 'assets',
            'cache'    => 'cache', // Name of your cache component
            'baseUrl'  => '',
            'filesystem' => [
                'class'  => creocoder\flysystem\AwsS3Filesystem::class,
                'key'    => 'xxxxxxxxxxxxxxxxxxx',
                'secret' => 'xxxxxxxxxxxxxxxxxxx',
                'region' => 'ap-southeast-1',
                'bucket' => '',

Do you get any error when executing it?

nope, my site works fine. no errors in logs either. only thing is i have to upload the assets manually.