In this particular case the error is produced, because I have just opened page.html
in a browser on my machine (i.e. I have not served it via server), thus /
is interpreted as local machine's root. If I have served the project, then /
would be interpreted as project's root, and there would be no error.
A little more elaborate explanation/illustration.
Given this structure:
/root
/static
script.js
page.html
Here are what different paths (in page.html
) will refer to:
/
— root directory, it might mean/root
, but also might mean the root of current environment (see explanation at the beginning of this answer)./
— current (the one wherepage.html
resides) directory, it just so happens that it is/root
in this case- it is worth mentioning that
./
can be omitted altogether, when referencing some file in current directory; so./static/script.js
is equivalent tostatic/script.js
- it is worth mentioning that
I have derived understanding needed for this answer, from:
- Aayush's answer to current question
- this answer, to another question of mine
- comments to this answer