A
A
Antago2014-11-05 17:35:04
Yii
Antago, 2014-11-05 17:35:04

How to change assets version after release in Yii2?

After releasing and clearing the assets folder, Yii2 creates a folder with the same name as before, despite the fact that the assets have changed. Accordingly, users have a cache. How to avoid it?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Antago, 2014-11-05
@Antago

protected function publishDirectory($src, $options)
    {
        $dir = $this->hash($src . filemtime($src));
        ....
    }

Judging by this code from AssetManager, the name of the target folder depends on the time the resource folder was last modified. But, as it turned out, this time does not change if only the contents of the files are changed. Those. the last modified time of a folder is independent of the last modified time of the files inside it.
Crutch option - create / delete some temporary file / folder in the resource folder

Z
Zohei, 2014-11-05
@Zohei

It is also interesting how this is done using the resource manager. I myself have always used the following trick: I specify the version number in the file path, for example, css/main.css?v=1.3
or js/main.js?v=2.29

A
Alexander Zelenin, 2014-11-06
@zelenin

the name of the directory in the assets folder - a hash that depends on the creation of the folder. Accordingly, by clearing the assets folder, you will recreate all the assets.

P
phpnt, 2015-03-06
@phpnt

Adding CSS, JS, JQuery and other resources to Yii... - clear assets

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question