Laravel mix - Versioning does not work
Asked Answered
F

1

7

I'm working on a fresh project using Laravel 5.6 using [email protected]. When I compile my assets using npm run production, they are not suffixed like they should

Note

Even when removing the if mix.inProduction() the versioning does not work

Questions

Am I the only facing this issue ? What should I do ?

webpack.mix.js

let mix = require('laravel-mix');
mix.js('resources/assets/js/app.js', 'public/js')
 .sass('resources/assets/sass/app.scss', 'public/css')
 .copyDirectory('resources/assets/images', 'public/images');

if (mix.inProduction()) {
  mix.version();
}
Frivolity answered 26/8, 2018 at 23:50 Comment(1)
currently having same issue as well. (my laravel-mix is 2.1.14)Squeteague
S
10

Laravel 5.6's mix works differently now. Instead of suffixing your compiled files with hashes, it now uses a url query in trying to access your assets.

Try opening your browser dev tools and look at how your page includes your assets. It will append an id param in the URL.

e.g. GET /js/app.js?id=<SOME_HASH_HERE>

Squeteague answered 28/8, 2018 at 4:21 Comment(3)
So you do confirm that cache busting is working right ?Intellection
Yes. To inspect it yourself, look at your browser's dev tools.Squeteague
@LéoCoco NB: you must use <script src="{{ mix('js/app.js') }}"></script> instead of <script src="{{ asset('js/app.js') }}"></script> now to get correct resource URL with id.Oxley

© 2022 - 2024 — McMap. All rights reserved.