How to Include Scripts on Specific Pages in Laravel

If you want to inlcude an external file, you can do the below:

There are just 2 steps:

Stack them in your app

@stack('choicesjs-scripts')

Push them on the specific page you want them to load

@push('choicesjs-scripts')
    <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/choices.js/public/assets/styles/choices.min.css"
    />

    <script src="https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js"></script>
@endpush

If you want to inlcude an internal file, residing inside the resources folder for a single blade

First stack in the layout file - be it app.blade.php or guest.blade.php

@stack('my-js')

Then push it into the individual target blade

@push('my-js')
	@vite(['resources/js/myjs.js'])
@endpush
comments powered by Disqus