Tutorial :is there a difference between absolute and relative paths when pointing to certain files on your html?


our office just got this new guy with lots of experience and kept insisting that we stop using absolute paths like:


when pointing to a path of our image when it resides next to the file that calls it say we could have just used:


but the reason why we used absolute paths before was to prevent deadlinks when we put another page in another directory, instead of explicitly typing

"../../" OR "./"

so is there really a difference when using them?
he said that each absolute urls is a separate request to the server.. but i've been using this method ever since and i can safely assure an expected fast response time, can anyone enlighten me?


Everything is a separate http request to the server. Relative or absolute it does not matter.

Of course, if the absolute url points to the same website but on a different host, then this may speed up things because it breaks the 2 concurrent http requests limit. e.g your site is at www.example.com and you serve all your images from static.example.com.

Another way to prevent the broken links issue you mention is by virtual URLs: /images/foo.png


Using relative paths make it possible for you to move your entire webapplication to another domain and/or folder without fixing every path.


Relative paths make for smaller HTML, resulting in less bandwidth consumption.

Relative paths are context friendly, meaning both "site.com" and "www.site.com" will work equally well, without the need for redirects from "site.com" to "www.site.com".


Absolute paths would be root absolute and versatile enough that you can later on move the file to another directory and the links would still work. And if you ever change the domain name, no problem, links still work.


Relative paths would be relative to the page you're on, and breaks if you ever move the file outside of its current directory.


Slapping on the domain part would make it an absolute URL.


Which is good if you have a scraper come along and then they would be able to link back to your own site so that when you check the referrer logs, you know who to go about sending that take down notice to.

Difference between the two would be how much more busy work you want to create for yourself later on.


I prefer to parse Request.RawURL manually to avoid collisions with urls


There might be a bit of a cargo-cult thing going on there.

Where I work, we were told by the server techs that absolute URLs did cause delays, because there was load-balancing involved. An absolute URL would go back to the switch and be relayed to one of four servers, whereas a local one wouldn't.

So it might have been true at his old work place. Whether it's true at your workplace is for you to find out.

But if he can't explain why he's saying it, it's a folk-belief until proven otherwise.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »