Laravel Mix Preload

Laravel Mix Preload

Laravel Mix Preload is a Laravel package by Sebastian De Deyne and Spatie that adds preload and prefetch links based on your Mix manifest file. This package exposes a blade directive that renders links based on chunks names with “preload” and “prefetch”.

Here’s the gist of what you need in your layout template:

    <title>Preloading things</title>


Which would render something like the following depending on the chunk names in the mix-manifest.json file:

<link rel="prefetch" href="/css/prefetch-otherpagecss.css" as="style">
<link rel="preload" href="/js/preload-biglibrary.js" as="script">
<link rel="preload" href="/js/vendors~preload-biglibrary.js" as="script">

As mentioned in the project’s readme, if you are unfamiliar with the concepts around prefetch and preload, check out Addy Osmani’s article Preload, Prefetch And Priorities in Chrome. Although you should read through the article, I like the following summary for when you should preload vs. prefetch:

Preload resources you have high-confidence will be used in the current page. Prefetch resources likely to be used for future navigations across multiple navigation boundaries.

You can learn more about this package, get full installation instructions, and view the source code on GitHub at spatie/laravel-mix-preload.

Filed in: News


Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Laravel Developer
FPV Exchange
Senior Full-Stack Developer
Remote, USA Only
Senior PHP Developer
Cary, NC
Backend PHP Developer
Engineering Director
Vancouver or remote (EST/PST preferred)
Engine Digital