I Just have a component and I want to add component script code at the bottom of main page cause it make loading page faster. how can I do this?
point: each script must be written on its component file.
I Just have a component and I want to add component script code at the bottom of main page cause it make loading page faster. how can I do this?
point: each script must be written on its component file.
you can write this in your parent component @stack('scripts'), and in your child component you can write like this @push('scripts).
your child component code will be like this
@push('scripts')
<script src="example.js"></>
@endpush
it will only push the scripts to the parent component when you load the child component.
create a blade file where you want to put all your script link. Let I have created a file inside my resource directory and named it like javascripts.blade.php .The file may look like this.
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<script>
window._token = '{{ csrf_token() }}';
</script>
@yield('javascript')
notice that I put @yield('javascript') at the bottom. Now you can use it inside <body></body> tag just using @include(javascripts) or if you're script file is inside a folder you can use @include(folderName.javascripts)