Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Should I try to refactor code to use Mix?

I'm working on a Laravel project that seem to have been written not according to guidelines. I try to fix some stuff there. One of the things I noticed is that there is no use of Mix.

There is only the default lines in the webpack.mix.js:

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css');

But even that is not used. They just put everything directly to the public folder.

What would be the benefits of trying to move everything to use Mix? *Using Laravel 6

0 likes
4 replies
Tray2's avatar

The benefit is that you would get a minified files in production, and they would be joined into a single css file, if there is more than one. The same would go for JavaScript.

1 like
Ligonsker's avatar

@Tray2 But what happens for example, if there are 2 pages and one of them uses 3 JS files and the second page uses only 1 of these 3 files. It means that Mix will turn these 3 files into 1 minified file and even the page that uses 1 JS will actually load the 3 minified ones?

Can't there be a situation where many JS files even when minified are still larger than 1?

Tray2's avatar

@Ligonsker Sure, that is a possibility, however the loading of one js file instead of three is done once, and then it will get it from the cache. So one is usually preferable.

1 like

Please or to participate in this conversation.