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

okaufmann's avatar

How do I publish my public assets in a clever way with Laravel and Laravel Mix?

Hi,

I'm using Laravel Mix in several Projects and always get to the same questions.

  • Should I add my compiled/transpiled js and css to git?
  • Or just the minified versions (the dev build are often a couple of megabytes) and how to identify them?.
  • Or should i never version assets in public folder?
  • But then how do I publish them with a new Verison?

I would like to hear your suggestions, how do you handle this?

Thank you.

0 likes
5 replies
Cronix's avatar

I commit both the compiled minified and regular versions to git. In the master template it checks to see if it's production, and loads minified versions, otherwise it uses regular versions.

@if (App::environment('production'))
    <script src="{{ mix('/js/file.min.js') }}"></script>
@else
    <script src="{{ mix('/js/file.js') }}"></script>
@endif

I version them with mix, so you need to include the /public/mix-manifest.json file in your repo as well and then just use <script src="{{ mix('/js/file.js') }}"></script> and in the browser it outputs the versioned file with the cache-busting querystring (/js/file.js?laksjwerlkjasaslkjf)

There are a lot of ways to do this, but that's what I usually do.

tykus's avatar

Imagine your diffs if your entire compiled js and css were in version control?

For me, only the uncompiled assets are in version control; the compiled versions are artefacts of a build process which can be handled during deployment.

okaufmann's avatar

@Cronix: But does that not blow up your git repo in any way? As mentioned before, unminified e.g. vendor.js begome often more than 2-3 MB big? Is there any way to name the mainfest file?

@tykus I never open the compiled files still less diff them. I have the source files e.g. written in typescript and just version them yet. How do you put your artifacts then to your app ? by hand via ssh?

tykus's avatar

What I meant was your git diffs will be huge because your entire compiled JS and CSS will be changed everytime you build.

My deployment process runs composer install for Laravel's dependencies and npm run production to compile assets.

okaufmann's avatar

Yeah, I did try compile all assets via forge on the server as well. But some servers are too weak to let me run mix on it (insufficient memory).

Further I have to deploy on some shared hoster's server, where I can connect via SSH but can't use node because it isn't installed (And I'm not permitted to install it).

I think I go the Way with the .min. files are added to git and the other ones aren't. I never diffed compiled files yet, so that doesn't matter for me. And it doesn't take to much space.

I also thought about wrapping the mix helper with something like mix_env where it does rewrite the files to the filename.min.js pattern. But this must prove itself first.

Please or to participate in this conversation.