skip to Main Content

Working on my project, the JS script file only loads around half the time which is very frustrating. The error I receive is

localhost/:252 GET http://localhost/js/script.js net::ERR_ABORTED 404 (Not Found)

I require the file at the bottom of the footer, which is in a blade component used on every page:

<x-footer />
</body>
<script src="{{ asset('js/script.js') }}"></script>
</html>`

I have tried moving the script file, renaming it, having it hard coded into each page instead of a blade component and still nothing works

Permissions of my public folder:

    total 32
0 drwxr-xr-x  11 brandon  staff   352  4 Nov 14:35 .
0 drwxr-xr-x  30 brandon  staff   960  4 Nov 14:33 ..
8 -rw-r--r--   1 brandon  staff   603 28 Oct 14:38 .htaccess
0 drwxr-xr-x   4 brandon  staff   128  4 Nov 14:33 build
0 drwxr-xr-x   3 brandon  staff    96  3 Nov 15:55 css
0 -rw-r--r--   1 brandon  staff     0 28 Oct 14:38 favicon.ico
8 -rw-r--r--   1 brandon  staff    21 11 Nov 15:57 hot
0 drwxr-xr-x   6 brandon  staff   192  3 Nov 16:08 img
8 -rw-r--r--   1 brandon  staff  1710 28 Oct 14:38 index.php
0 drwxr-xr-x   3 brandon  staff    96 11 Nov 15:53 js
8 -rw-r--r--   1 brandon  staff    24 28 Oct 14:38 robots.txt

and the JS file

 0 drwxr-xr-x   3 brandon  staff     96 11 Nov 15:53 .
 0 drwxr-xr-x  11 brandon  staff    352  4 Nov 14:35 ..
24 -rw-r--r--   1 brandon  staff  11937 14 Nov 11:54 script.js

FIXED! It appeared to be a docker issue. I had to docker compose down and docker compose up the container, which fixed it.

2

Answers


  1. Chosen as BEST ANSWER

    FIXED! It appeared to be a docker issue. I had to run docker compose down and docker compose up the container, which fixed it.


  2. Move your JS files into the /public folder in your project, as the asset(...) method uses the path from the public folder.

    So your JS files should be in /public/js/script.js

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search