Laravel - Compiling Assets - Vendor Extraction

One potential downside to bundling all of your application-specific JavaScript with your vendor libraries such as React and Vue is that it makes long-term caching more difficult. For example, a single update to your application code will force the browser to re-download all of your vendor libraries even if they haven't changed.

If you intend to make frequent updates to your application's JavaScript, you should consider extracting all of your vendor libraries into their own file. This way, a change to your application code will not affect the caching of your large vendor.js file. Mix's extract method makes this a breeze:

    mix.js('resources/js/app.js', 'public/js')

The extract method accepts an array of all libraries or modules that you wish to extract into a vendor.js file. Using the snippet above as an example, Mix will generate the following files:

To avoid JavaScript errors, be sure to load these files in the proper order: