views:

63

answers:

6

If I display abc.jpg 20 times on a web page, does loading of the web page cause 20 http requests to the abc.jpg? Or it depends if I am using relative or absolute paths?

Thanks

+2  A: 

It depends on the web browser, but any modern browser should only request it once.

Nick Fortescue
+2  A: 

It's down to the browser. A poorly written browser may request the same file multiple times, but any of the widely-used browsers will get this right. It shouldn't matter whether they are using relative or absolute paths (though mixing between relative and absolute paths on the same page might trip up some browsers, so you should probably avoid it).

Tim
Resolving relative URLs is a fundamental requirement for browsers.
Gumbo
I was wondering whether a browser might de-duplicate the image URLs before resolving them to absolute URLs. It doesn't sound likely, but it would make sense to be consistent anyway.
Tim
+2  A: 

It is up to the browser. A modern browser will try hard to cache the image. Use consistent URL format in your requests when possible - consistent capitalization, don't use "www." one time and no "www." another time, etc.

Igor ostrovsky
+1  A: 

Download Firebug and use the 'Net' tab to inspect all requests.

For this case, I agree with the other answers, any modern browser with proper settings should cache it.

chelmertz
This is a really good suggestion to see what is being requested from the browser, the time to first byte, and the time to last byte.
Stevko
A: 

It does depend on the browser settings but it also depends on what the web server tells the client to do with the image.

See this, it's quite complicated http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html

John Burton
A: 

While I agree with the above statements, I suggest looking at your web server access log for the target image and comparing the referring page and browser fingerprint.

You will possibly see lots of hits to HEAD rather than GET in order to make sure the file cache is up to date.

Stevko