D
D
DrFreez2014-07-23 08:15:40
css
DrFreez, 2014-07-23 08:15:40

Yii, CSS & JS. How to organize version control when caching?

We expose caching for scripts and styles in nginx

location ~ \.(js|css)$ {
     expires max;
}

As a result, now, in order for the browser to pull up the changed js / css, you need to change the url. Add ?r123 for example (connected via registerPackage). Which is somehow not very convenient if the project has a lot of styles and scripts.
I looked at the assetManager, but then I realized that the path in the end is always the same, and this will not help. What is the best way to do this? Are there examples?
I read habrahabr.ru/post/139166/, found out it is necessary to do touch /path/to/your/website/protected/assets. Is it somehow possible without it? The article wrote that the rails have already solved this problem. What is this solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene Burmakin, 2014-07-23
@Freika

aaronfrancis.com/blog/2013/6/19/yii-and-the-asset-... isn't that an option? Rails uses the Assets Pipeline to version elements and give them unique names when compiled, so you can see the latest changes even with caching enabled.

V
Vit, 2014-07-23
@fornit1917

Add ?r123 for example (connected via registerPackage). Which is somehow not very convenient if the project has a lot of styles and scripts.

Conveniently. It can even be automated.
I looked at the assetManager, but then I realized that the path in the end is always the same, and this will not help.
Not
Not really, by default, yii itself tracks that the file has been changed and re-uploads it to asset in another folder. The script will now be published with the new path. Well, yes, the old one must be removed by hand. On a development machine, this is not critical, but on a production machine, it can be automated when updates are rolled out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question