views:

165

answers:

3

I noticed a performance degradation when in my webpages I use the full HTTP URL to load an image.

Let's say my website is on mydomain.com. Let's say images are all in mydomain.com/imgs directory.

It seems it's slower when I place images in the webpage using the full URL format:

<img src="http://mydomain.com/imgs/someimg.jpg"&gt;

rather than doing:

<img src="/imgs/someimg.jpg">

Same issue for loading JavaScript/CSS files.

Is the web server on mydomain.com taking more time to get images/fiels when using full http url (still on mydomain.com) compared to document root paths???

A: 

You problem is likely just that there is overhead in DNS lookups or something when accessing locally. Internet users will not notice the difference.

Gabe
+3  A: 

Oh this could be a slap on the forehead moment.

  • When running locally and using the relative path the files are coming off your hard drive.
  • When running locally and using an absolute path to a live server its having to go over the wire out on to the internet.
Pete Duncanson
If this is true than also on the online web server would be exactly the same, so using the full url makes eveything to run slower. Is this what you are saying?
Marco Demajo
Internet users cannot load the files directly off your hard drive, so it will run the same speed for them regardless.
Gabe
Yes, but the question is will the web server take less time to get the images to be sent to the client if it looks for relative paths or if it goes via http full url???
Marco Demajo
no. the web server returns the html document to your browser which will then send more http requests for the image/css/js elements included in the document. there will be no performance difference on a live site.
Adam Pope
A: 

There is no difference. The browser always needs the absolute URL to retrieve the resource. So the relative URL needs to be resolved to an absolute URL. But that is absolutely negligible.

Gumbo
Your are perfectly right, I'm rally flipped out! It's true that's the browser that asks the server for files not the servers reading the page and sending them down. Thanks, thanks, thanks! I really asked a silly question! :(
Marco Demajo