Difference between Relative path and absolute path in javascript
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.
What is the difference between an absolute and a relative path?
Say you were giving directions to a spot. You have two methods you can describe getting to the location:
- Relative to where you stand,
- Relative to a landmark.
Both get you to the same location, but the former doesn't always work ("take a left, then a right, go through two lights then take another right" wouldn't necessarily work from the next town over, but works from where you stand). That's essentially the difference.
If you have C:\Windows\System32
, that's an absolute path. If you have Windows\System32
, it will only work so long as you're starting from C:\
. If you start in C:\Program Files
you would need a ..\
to get there correctly.
However, no matter where you are on the hard drive, C:\Windows\System32\
is a definitive way to get to that folder.
What is an Absolute Pathname vs a Relative Pathname
You are correct in your assumption.
the relative path is the path minus the output from pwd.
the absolute path always starts from the root "/" directory.
example:
if you have just logged in you are in your home directory - /home/user - and have a file text.txt in your home directory.
the relative path is text.txt
the absolute path is /home/user/text.txt
What is the difference between Relative and Absolute paths in Aspnet MVC?
Absolute Path:
An absolute URL path. An absolute URL path is useful if you are referencing resources in another location, such as an external Web site.
<img src="http://www.contoso.com/MyApplication/Images/SampleImage.jpg" />
Relative Path:
A site-root relative path, which is resolved against the site root. Site-root relative paths are useful if you keep resources that are used throughout the site, such as images or client script files, in a folder that is located under the Web site root.
The following example path assumes that an Images folder is located under the Web site root.
<img src="/Images/SampleImage.jpg" />
For More Refer:
http://msdn.microsoft.com/en-us/library/ms178116.aspx
Coming to your Question:
<img src="@Url.Content("~/Content/themes/base/images/logo.png")" alt="Koiak Basic Site" />
Here because of using "~".It adds "server" path(i.e; your application path)" to your url. That means it takes img src
as "yourapplicationPath/Content/themes/base/images/logo.png"
<img src="/Content/themes/base/images/logo.png" alt="Koiak Basic Site"/>
Here it takes as it is. i.e;"/Content/themes/base/images/logo.png"
For more refer this:
why use @Url.Content
http://digitalzoomstudio.net/2012/04/01/what-is-the-difference-between-absolute-and-relative-paths-urls/
What is the difference between / and ~/ relative paths?
Using Absolute Versus Relative Paths for Images
Using absolute paths forces the web server to establish a connection, send and receive the HTTP requests. If using relative, the connection is already established, so it doesn't have to go through that logic (hence increasing page load speed). You probably won't see an amazing difference, but every bit saved is a good thing, right?
Edit: After doing a quick test, the difference is extremely negligible, and doesn't seem to produce that great of a case for my answer. I created a test page with the same image twice, one with relative and one with absolute path: http://damonbauer.me/test/index.html.
Test One: Image w/ Absolute path in HTML code first: (click for larger version)
http://damonbauer.me/test/images/results1.jpg
The absolute path image took 869ms to load, while the relative path image, listed second in the HTML code, loaded in 635ms.
Test Two: Image w/ Relative path in HTML code first: (click for larger version)
http://damonbauer.me/test/images/results1.jpg
The absolute path image took 303ms to load, while the relative path image, listed first in the HTML code, loaded in 315ms.
My opinion? It's faster to load using relative. Even when listed after the absolute path image, it took only 12ms longer for the relative image to load. When the absolute path image was loaded second, it took it 234ms longer to load. In both cases, they are close, and it looks to me like it matters more about what loads first. Either way, I would go with relative, if only for portability's sake.
Relative paths or absolute?
It doesn't affect server performance.
With a relative path, your browser takes the URL and adds it to the URL path already in the address bar.
For example, if a page requested is: http://example.com/folder1/index.php
and it has a link pointing to folder2/index.php
and its clicked, then the page http://example.com/folder1/folder2/index.php
will then be requested from the server. The web browser does the conversion for you.
Related Topics
Difference Between Var_Dump,Var_Export & Print_R
PHP - Extracting a Property from an Array of Objects
How to Change the Woocommerce_Form_Field HTML Structure
Long Integer Is Transformed When Inserted in Shorter Column, Not Truncated. Why? What Is the Formula
Whats the Easiest Way to Determine If a User Is Online? (Php/Mysql)
How to Return a Proper Success/Error Message for Jquery .Ajax() Using PHP
How to Bind SQL Variables in PHP
Applied Coupons Disable Free Shipping Conditionally in Woocommerce
How to Access a PHP Object Attribute Having a Dollar Sign
Storing Database Connection in a Session Variable
Comma-Separated String to Array
Proper Repository Pattern Design in PHP
Laravel Checking If a Record Exists
MySQL - Insert Date Range into Date Columns If Dates Don't Overlap with Existing Ones
MySQL Select from Tables Based on Multiple Rows
Bind Param with Array of Parameters
Error: MySQLnd Cannot Connect to MySQL 4.1+ Using the Old Insecure Authentication