cristimocean's avatar

Mix documentation wrong/outdated ?

The docs say "The version method will automatically append a unique hash to the filenames" and that I should use the mix helper to detect file names () but that not seem to be the case. My javascript is NOT hashed after adding .version , it's still under public\js\app.js and layout.app is loading it just fine with asset('js/app.js') , no mix helper needed ...

0 likes
6 replies
Braunson's avatar

No it is correct, I can confirm as I use .version() and it does indeed hash my .js/css files. What does your Laravel Mix webpack file look like, can you post it? also what version of Laravel Mix do you have in your package.json/package-lock.json?

Snapey's avatar

yes, but if you want it to be versioned then you MUST use the mix version helper in your view.

<script src="{{ mix('/js/app.js') }}"></script>

then view the html page source and you should see the version.

Snapey's avatar
Snapey
Best Answer
Level 122

I think the docs are wrong in that it says;

After generating the versioned file, you won't know the exact file name. So, you should use Laravel's global mix function within your views to load the appropriately hashed asset. The mix function will automatically determine the current name of the hashed file:

but that is not how it works these days. Your app.css and app.js have an ?id= appended which corresponds with the latest build.

since mix() is only responsible for appending the current id, then the files still work as app.css and app.js without the addition of the id, but of course with no cache busting

1 like
cristimocean's avatar

webpack.mix.js

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .version();

mix-manifest.json

{
    "/js/app.js": "/js/app.js?id=c8fd755425ce3cdde8a9",
    "/css/app.css": "/css/app.css?id=30709468585d3b432ca4"
}

package.json

     "laravel-mix": "^5.0.1", 

I am using laravel 7

cristimocean's avatar

A slightly unrelated question: after I removed mix.version() and the mix() helper and I compiled again with "npm run watch" Chrome stopped caching ! I checked the network tab in chrome devtools and it no longer says (memory cache) but it's downloaded each time instead. Any idea what caused this ? Chrome used to serve from cache before I played with version()/mix() ...

Please or to participate in this conversation.