javascript - Is there any way to force browser to SHOW CACHED IMAGE, without asking server, on newly created img? -


i'll try short , clear possible:

example html:

<span id="xyz">    <img src="/somescript.php?x=1&y=2" /> </span> 

javascript (attached window.onload, executes after on page loaded):

    tmp=document.getelementbyid('xyz');     tmp.innerhtml='<img src="/somescript.php?x=1&y=2" />'; 

somescript.php generates new image on request (even same get parameters) , returns no-cache header (as intended , shouldn't changed).

current behaviour: browser (tested in chrome) asks server /somescript.php?x=1&y=2 each newly created image.

is there way so, newly created image show cached content if image such src has been loaded before without trying ask server second time (because server return new image, instead of old)?

p.s.: it's more of theoretical question, because i know, common solution check/alter old img's src instead of creating new one, want know whether there answer actual question.

p.p.s: haven't been able find answer on google/stack because popular question same keywords opposite mine.


Comments