I'm trying to load external scripts from a folder into my createnew.html
file and I keep getting this error saying it cannot be found:
Failed to load resource: the server responded with a status of 404 (Not found)
I'm trying to load the scripts in the head
of my code, like this:
<head>
<!--C3 CSS script-->
<link href="./scripts/c3.css" rel="stylesheet" type="text/css">
<!--C3 JS script-->
<script src="./scripts/c3.min.js"></script>
</head>
My files are arranged like this:
->public
->views
-createnew.html
->scripts
-c3.css
-c3.min.js
Please help me understand why this doesn't work.
As this question became more popular than expected, I decided to point other problem-havers in the right direction:
Let's say you have organized your files like this:
- server.js
-> MyWebsite(folder)
- index.html
-> js(folder)
- myscript.js
The paths you use are relative to the "working directory" you are in.
- When not using a server, and only developing websites locally on your computer, this working directory will be the relative path from your
index.html
file to your scripts. In this case it would be./js/mysript.js
. - When using a server you need to tell it where this working directory is. In the case of Node.js you would do something like this
app.use(express.static('./MyWebsite'))
and your js files would be referenced by/js/myscript.js
Notice that when loading from a server you prefix with /
instead of ./
since the /
really is just a part of the URL to your file hosted by your server, while ./
is specific to the file system.