5

I have css under App/resources/css by default

when I open Login and Register page css is not loading. This is default css and js link on my app.blade.php

<script src="{{ asset('js/app.js') }}" defer></script>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">

I did this

<link href="{{ URL::asset('assets/css/a.css') }}"  rel="stylesheet">

and also tried

<script src="{{ asset('resources/js/app.js') }}" defer></script>
<link href="{{ asset('resources/css/app.css') }}" rel="stylesheet">

What shall I do to make it work.??

4
  • resources folder data you cannot access by asset() read this laravel.com/docs/8.x/mix Commented Feb 1, 2021 at 10:42
  • 2
    You need to put it on /public directory, not /resources directory. Ex : /public/css/app.css then you can access {{ asset('css/app.css') }} Commented Feb 1, 2021 at 10:43
  • @sta:: I tried moving the css and js to public folder but nothing changes. I would be grateful If u provide ma a solution to access a css and js file. Thank You Commented Feb 1, 2021 at 10:46
  • @KamleshPaul- Is there any other way so that I can put css and js files in public folder and access it? Thank you Commented Feb 1, 2021 at 10:48

2 Answers 2

3

Move all your CSS and JavaScript to the public folder so that your structure becomes something like

public/
    |--- css/
    |---js/

Now to use your CSS and JavaScript from your new location do something like

<script src="{{ asset('js/app.js') }}" defer></script>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">

This works because the asset() blade helper already looks from the public directory so you start your CSS and JavaScript URL construction from that point on

Sign up to request clarification or add additional context in comments.

1 Comment

Shouldn't this happen automatically though? When you install the ui and auth, why doesn't it also move the css and js to /public?
2

I would recommend to always use the mix helper in Blade like this

<script src="{{ mix('/js/app.js') }}"></script>

as it additionally properly takes care of versioned assets. Please make sure you either ran npm run dev or npm run prod (see Compiling assets) to generate the public/css/app.css and public/js/app.js files from the ones located in resources.

1 Comment

Hi, I am running into similar problem while deploying on Vercel. I have done npm run prod and I can see both css and js files in the public folder. I have deployed it but on the vercel link it shows 404 on both files. Any idea?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.