JQuery.load does not start if image is cached (Chrome only)

for some reason, jQuery.load does not start if the image is saved in the cache (Chrome only).

here jsfiddle

how can i fix this?

+4
source share
3 answers

This is because if the current src and new src are the same, it does not load the new image, since both of them are the same. The hack for this makes the current src value empty.

$("#btn").click(function(){ $("#tst").attr('src',''); $("#tst").attr('src','https://www.google.co.il/images/srpr/logo3w.png'); }); 

jsFiddle demo link

+6
source

For example, you can use a timestamp:

  var timestamp = new Date().getTime(); $("#image_test") .attr("src", "http://www.sandiegovips.com/wp-content/uploads/2014/05/test-image.jpeg?timestamp="+timestamp) .load(function() { alert("image loaded!"); }); 
 <img id='image_test' src=""/> 
+1
source

You can bypass the cache by including a timestamp in the image URL. This will cause the cached image to be updated every time it is requested.

0
source

All Articles