spatie/laravel-mix-preload
Laravel package that adds a @preload Blade directive to automatically output preload/prefetch tags from your mix-manifest.json. Mark chunks by including “preload” or “prefetch” in the filename to optimize asset loading.
mix-manifest.json, aligning with modern web performance best practices.composer require spatie/laravel-mix-preload).@preload in <head>).preload-/prefetch-).mix-manifest.json accuracy. Build failures (e.g., incorrect chunk names) could break preloads.
@preload only on specific pages)./js/app.[hash].js). Misconfiguration could lead to 404s.
MIX_APP_URL and hashed paths in staging.vendors~preload-biglibrary.js) impact initial render time vs. subsequent page loads?resourcehinting in Chrome DevTools).@preload) integrates cleanly.mix-manifest.json to identify candidate assets for preloading/prefetching.mix-manifest-path() to inspect generated paths.@preload on high-traffic pages (e.g., homepage, checkout).preload- prefix for critical JS, prefetch- for future pages).@if(request()->is('home')) @preload @endif).config('preload.enabled')) for gradual rollout.| Step | Priority | Dependencies | Notes |
|---|---|---|---|
| Install package | High | Laravel Mix | composer require spatie/laravel-mix-preload |
| Update Blade | High | None | Add @preload to <head> |
| Manifest audit | Medium | Build process | Verify chunk naming conventions |
| Pilot rollout | Medium | Monitoring setup | Start with prefetches |
| Optimization | Low | Performance data | Refine based on Lighthouse metrics |
| Documentation | Low | Team onboarding | Add preload strategy to runbook |
mix-manifest.json validation (e.g., jsonlint.com).preload-, prefetch- prefixes).@preload).| Failure Scenario | Impact | Mitigation Strategy |
|---|---|---|
Missing preload- prefix |
Silent failure (no preload tags) | CI linting for manifest chunk names |
| Incorrect hashed paths | 404 errors | Test with MIX_APP_URL and hashed paths |
| Over-aggressive prefetching | Bandwidth waste | Limit prefetches to high-probability routes |
| Browser ignores preload | No performance gain | Feature detection + fallbacks |
| Manifest generation fails | Broken preloads | CI validation of mix-manifest.json |
| CDN cache invalidation issues | Stale preloaded assets | Ensure cache headers respect asset has |
How can I help you explore Laravel packages today?