Van Adrian Cabrera Van Adrian Cabrera - 6 months ago 26
PHP Question

What is the importance of using the .version in elixir (Laravel)?

I'm studying laravel framework and I encountered the elixir function that's using

.version
e.g.

elixir(function(mix) {
mix.sass('app.scss')
.version('css/app.css');
});


I want to know if what's the importance of this function (in what situation)?

Answer

The importance and use case of using version with Laravel Elixir is already pointed out in the documentation

Many developers suffix their compiled assets with a timestamp or unique token to force browsers to load the fresh assets instead of serving stale copies of the code.

Sometimes you run into situations where browsers do not fetch the new content/version of a CSS/JS file. With appending a unique stamp to the CSS/JS file name the browsers are aware of the new file (new file name) and load the new asset