Skip to main content

How to fix jQuery.load() in IE for cached images

Solution 1, removing the cache by adding a datetime string to the image src:

   $('<img/>')
      .attr('src', 'image_url?' + new Date().getTime())
      .load(function() {
         alert('Image loaded');
      });

This solution works almost everytime but sometimes it has introduced even more IE weirdness for me. It can also be an costly affair if you have many visitors why I have tried alternatives. I ended up with solution 2 and it seems to work everytime! :)

Solution 2 (improved), adding the src after the load() call seems to do the trick as well and will keep the cache:

   $('<img/>')
      .load(function() {
         alert('Image loaded');
      }).attr('src', 'image_url');

 

 

 

Does google index lists created with angular’s ng-repeat directive? 

One thought to “How to fix jQuery.load() in IE for cached images”

Leave a Reply

Your email address will not be published.