S
S
Sorin Ciobanu2017-08-16 17:39:57
Yii
Sorin Ciobanu, 2017-08-16 17:39:57

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

2 answer(s)
A
Andrey Tokmakov, 2017-08-16
@NPC

See assets

K
kalyabus, 2017-08-16
@kalyabus

In order for the file not to be cloned, you need to configure the assetManager component in the config:

return [
    ...
    'components' => [
        ...
        'assetManager' => [
            ...
            'linkAssets' => true,
            ...
       ],
       ...
    ]
];

Then files from AssetsBundle will not be copied, instead symlinks will be created on them
All files are cloned (or symlinked) to the folder specified in the basePath AssetsBundle variable, for example:
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 question

Ask a Question

731 491 924 answers to any question