Answer the question
In order to leave comments, you need to log in
How to load css and js in yii?
Created js file say alternative.js in /app/web/js/. The first time the script is called, it is cloned to an unknown location. And it is not possible to work with the file until you rename it. Navigating to site.domain/js/alternative.js also displays the file without changes. How to solve this problem? Clearing the cache didn't work.
Answer the question
In order to leave comments, you need to log in
In order for the file not to be cloned, you need to configure the assetManager component in the config:
return [
...
'components' => [
...
'assetManager' => [
...
'linkAssets' => true,
...
],
...
]
];
class FrontendAssets extends AssetBundle
{
public $sourcePath = '@app/_assets';
public $basePath = '@webroot/assets'; // вот сюда они будут сохраняться, @webroot - соответственно алиас пути, конфигурируемый в основном конфиге
public $css = [
'css/styles.min.css',
];
public $depends = [
'yii\web\JqueryAsset',
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question