In Laravel 5, I set up a simple external js file inside public/js/test.js
It has one line of code:
alert(1);
I included the file like so in view:
{{Html::script('js/test.js')}}
When the page load, I got
Uncaught SyntaxError: Unexpected token ILLEGAL
error from that javascript file.
I tested running the same test.js file in my MAMP setup, and it run fine. So, the file has no issue. I cannot figure out what in Laravel 5 is causing the issue.
Please help.
Put the .js file into the public directory and call it with Laravel's asset() like so:
<script type="text/javascript" src="{{ asset('js/bootstrap/bootstrap.min.js') }}"></script>
If you are using it in view make the file name with .blade.php extension ex: myjsfile.blade.php and call it with an include in any of your view files
@include('myjsfile.blade.php')
Hope that helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With