when using <script src = "example.js"> </ script> is it also necessary to specify the path where the javascript code is located? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

when using <script src = "example.js"> </ script> is it also necessary to specify the path where the javascript code is located?

26th Dec 2018, 2:30 AM
Carders Unidos
Carders Unidos - avatar
2 Answers
+ 2
You already gave a path to the script tag, "example.js" is a relative path that will check for the file in the same directory/folder the HTML document is located in. If you mean the absolute path (full path e.g. "C:/users/user/documents/......") then no it is not necessary and frowned apon actually.
26th Dec 2018, 2:39 AM
TurtleShell
TurtleShell - avatar
+ 1
Yes. Say if you had a folder called "Project" and it was setup like this: --------- [img] -> earth.jpg, moon.jpg, sun.jpg [scripts] -> app.js, example.js, script.js [styles] -> bootstrap.min.css, style.css index.html --------- (Where "[...]" indicates a folder and "->" indicates the files in that folder) In "index.html" to link to "example.js" you would want to use: <script src="./scripts/example.js"></script> (The "./" can be used to denote the current folder)
26th Dec 2018, 2:46 AM
LynTon
LynTon - avatar