1

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.

  1. 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.
  2. 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.

martin
  • 1,894
  • 4
  • 37
  • 69
  • try "/scripts/c3..." or "/views/scripts/c3..." – dandavis Jun 24 '15 at 20:53
  • @dandavis the last one worked, would you mind explaining why? – martin Jun 24 '15 at 20:56
  • 1
    full url paths often work better for using from many pages because it's the same path from anywhere. why it worked is that it pointed to the right path. it's hard to decipher your "ascii art" folder listing, but i'm guessing you were just a folder off or something... – dandavis Jun 24 '15 at 21:00

2 Answers2

0

Change

"./scripts/c3.css"

to

"scripts/c3.css"
Fenil Dedhia
  • 365
  • 2
  • 21
0

You can refer to this question about the relative path of files in HTML.
To refer to the current folder, ./ works only in non-strict doctype mode, while . works in both modes. So you may try "scripts/c3.css" instead of "./scripts/c3.css"

Community
  • 1
  • 1
llxxee
  • 59
  • 1
  • 6