In my Laravel 9 project that I am working on, I want to put a javascript file containing common functions in app.blade.php. As per How to include External CSS and JS file in Laravel 5.5, I placed the js file in public/js folder and included the following in app.blade.php
<!-- common js functions added by Ravi -->
<script src="{{ asset('js/common_js.js') }}" ></script>
However, this file is not getting included on the page, and the js functions included in the file are not available in console.
Could someone advise me how to include a js file so that it is available for all pages?
Thanks.
CodePudding user response:
run command
php artisan view:clear
CodePudding user response:
What i think is happening, is Laravels helper function asset()
is putting your Js file into an assets folder on the server.
So make sure your common_js file is found here /assets/js/common.js
as answered on this post: Laravel 5 assets links
CodePudding user response:
you need to check the path rendered by asset()
if it's not the correct path you can change the asset path from the .env
file ASSET_URL