views:

340

answers:

6

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

http://somesite.com/subdir1/images/filename.ext


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

./subdir1/images/filename.ext


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 "./"

recursively...
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?

+2  A: 

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

cherouvim
A: 

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.

/foo/monkey-wrench.song

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

../foo/everlong.song

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

http://example.com/foo/this-is-a-call.song

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.

random
A: 

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

+2  A: 

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

toxvaerd
even if its a dynamic website say we got this $siteurl = "http://somesite.com" and just echo siteurl for every object called
lock
@lock: you could even dynamically discover the $siteurl value from the http variables. Portability to the maximum :)
cherouvim
+1  A: 

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".

diciu
A: 

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.

AmbroseChapel