Manage Assets for action, controller or view

Hello

I purchased a premium template, but has many assets (css, js, img, etc) referencing everything in sight AppAsset.php unnecessarily overburden,

is there any way to manage it in more optimal way?

Hi,

I had the same requirement for the yii2-bootswatch-asset : a bunch of files were not needed and didn’t have to be published in the asset folder.

Have a look here : https://github.com/raoul2000/yii2-bootswatch-asset/blob/master/BootswatchAsset.php

As ypu can see in the init method, some folders are skipped : ‘2’,‘api’,‘assets’,‘bower_components’,‘tests’,‘help’,etc…

Same occurs for files based on the extension : ‘css’,‘eot’,‘svg’,‘ttf’,‘woff’,‘woff2’

Hope this helps

ciao

B)

You should use app assets when possible so you can minify them later. You can also create multiple app assets and only use the ones you need for the certain views/ layouts etc. You would also just put your theme js and CSS in them too not your images.

Take a look at the guide for App assets guide it shows you how to do everything.

I personally just put all of the themes’ assets inline in the main layout when developing. After the project is finished I move the assets to app assets and remove any that I don’t need. I also break them into different ones based on how and when I need to use them.