简体   繁体   中英

Laravel won't load my javascript file

I have a javascript file in /public/js/ called myjavascript.js .

I want to include it in my site.

So I did this:

@extends('something')

    @section('scripts')
        <script src="/js/myjavascript.js"></script>
    @stop

@section('content')
...

This work in other project but not in this new one. What am I doing wrong?

这样尝试

<script src="{{ asset('/js/myjavascript.js') }}"></script>

尝试这个:

<script rel="text/javascript" src="{{ URL::asset('js/myjavascript.js') }}"></script>

I think your code need to update like:

{!! Html::script('js/myjavascript.js') !!}

Hope this work for you!

<script src="{{ asset('/js/myjavascript.js') }}"></script> is perfect.

Check your APP_URL from .env file.

if your APP_URL=www.example.com then your source will be www.example.com/js/myjavascript.js

if your APP_URL=example.com/laravel then your source will be www.example.com/laravel/js/myjavascript.js
Check ' https://github.com/laravel/framework/blob/5.4/src/Illuminate/Foundation/helpers.php ' for more about asset helper function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM