Difference between Relative path and absolute path in javascript
Solution 1:
The path with reference to root directory is called absolute. The path with reference to current directory is called relative.
Solution 2:
What is the difference between Relative path and absolute path?
One has to be calculated with respect to another URI. The other does not.
Is there any performance issues occures for using these paths?
Nothing significant.
We will get any secure for the sites ?
No
Is there any way to converting absolute path to relative
In really simplified terms: Working from left to right, try to match the scheme, hostname, then path segments with the URI you are trying to be relative to. Stop when you have a match.
Solution 3:
Completely relative:
<img src="kitten.png"/>
this is a relative path indeed.
Absolute in all respects:
<img src="http://www.foo.com/images/kitten.png"/>
this is a URL, and it can be seen in some way as an absolute path, but it's not representative for this matter.
The difference between relative and absolute paths is that when using relative paths you take as reference the current working directory while with absolute paths you refer to a certain, well known directory. Relative paths are useful when you make some program that has to use resources from certain folders that can be opened using the working directory as a starting point.
Example of relative paths:
image.png
, which is the equivalent to.\image.png
(in Windows) or./image.png
(anywhere else). The.
explicitly specifies that you're expressing a path relative to the current working directory, but this is implied whenever the path doesn't begin at a root directory (designated with a slash), so you don't have to use it necessarily (except in certain contexts where a default directory (or a list of directories to search) will be applied unless you explicitly specify some directory)...\images\image2.jpg
This way you can access resources from directories one step up the folders tree. The..\
means you've exited the current folder, entering the directory that contains both the working andimages
folders. Again, use\
in Windows and/
anywhere else.
Example of absolute paths:
D:\documents\something.doc
E:\music\good_music.mp3
and so on.
Solution 4:
Relative Paths
A relative path assumes that the file is on the current server. Using relative paths allows you to construct your site offline and fully test it before uploading it.
For example:
php/webct/itr/index.php
.
Absolute Paths
An absolute path refers to a file on the Internet using its full URL. Absolute paths tell the browser precisely where to go.
For example:
http://www.uvsc.edu/disted/php/webct/itr/index.php
Absolute paths are easier to use and understand. However, it is not good practice on your own website. For one thing, using relative paths allows you to construct your site offline and fully test it before uploading it. If you were to use absolute paths you would have to change your code before uploading it in order to get it to work. This would also be the case if you ever had to move your site or if you changed domain names.
Reference: http://openhighschoolcourses.org/mod/book/tool/print/index.php?id=12503