1

I want to change an img src with jquery, without pulling an image from server again.

I do it with next chunk of code:

  var img = $(this).find('img');
  $('#preview .modal-body img').prop('src',img.prop('src'));
  $('#preview').modal();

But browser is trying to pull this image from a server again. how i can avoid it ?

RusAlex
  • 8,245
  • 6
  • 36
  • 44
  • 2
    If the src is the same, and assuming you have set your headers correctly, it won't go back to the server - it should hit your browser cache instead – sazh Mar 22 '12 at 19:24
  • it touches a server about last modified header. and uses cache if not modified. – RusAlex Mar 23 '12 at 09:03

1 Answers1

0

maybe you can replaceWith I havent tested...

var img = $(this).find('img');
$('#preview .modal-body img').replaceWith(img);
$('#preview').modal();
Johnny Craig
  • 4,974
  • 2
  • 26
  • 27