+ 1
What is relative path and absolute path?
2 ответов
+ 1
*Relative Path*
❓"How do we get to the destination from the current location?"
✳ The path varies based on your current location.
*Absolute Path*
❓"Tell me the direct path to the destination with respect to the root."
✳ Single/universal path. The root depends on the context used, for example in Windows, the most common absolute path to the system files start with C:\.
Let's say we have the following folder structure and if we want to include the resources into index.html:-
root
|_ css
|_ style.css
|_ script
|_ run.js
|_ index.html
The relative path will be:-
css/style.css
script/run.js
i.e. From the same level as index.html, go into css folder and locate the file style.css.
and the absolute path will be:
root/css/style.css
root/script/run.js
+ 1
Absolute path is the explicitly defined path to the file/folder starting from the root of the operating system.
On windows you might see something like:
C:\Users\Public\Desktop\folder\file.ext
Relative path is the path to the file/folder from the current file location. You use a single . to denote the current directory and a double .. to go up one directory. So to access a file that is in a folder that is at the same level as the current files parent directory you would use something like:
./../folder/file.ext
Whenever possible you should use a relative path over an absolute path, as they are more platform independent.