1

I can't figure out why my css and js doesn't load. I am using node and rand the npm install and npm run dec commads multiple times and also tried writing the paths like this :

    <!-- Styles -->
    <link rel="stylesheet" href="{{ asset('public/css/app.css') }}">

    <!-- Scripts -->
    <script src="{{ asset('public/js/app.js') }}" defer></script>

and like this:

    <!-- Styles -->
    <link rel="stylesheet" href="{{ asset('css/app.css') }}">

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>

And still my page looks like this: enter image description here

This is my main paige that loads up first when you enter the site. When i go into the "view page source" and click on the links for the css and js files it returns a 404 page. All the other pages i have are experiencing the same issue.

  • if you are referencing to the ```public``` folder, it should be ```{{ asset('css/app.css') }}```. Check that those files actually exist in your public directory – Innovin Sep 21 '22 at 16:57
  • The fact that you cite public/ in your asset URLs probably means that your hosting is off. You should never see public in any URLs if you have correctly specified it as the _document root_ – Snapey Sep 21 '22 at 17:03
  • Does this answer your question? [Including a css file in a blade template?](https://stackoverflow.com/questions/45279612/including-a-css-file-in-a-blade-template) – Abdulla Nilam Sep 21 '22 at 17:07

1 Answers1

0

Your asset url should point to your /public path. Use asset('css/app.css') and asset('js/app.js'). You can configure the asset url by setting the ASSET_URL variable in your .env file.

Don't forget your rewrite rules. Something like...

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]