Given a number of images (animation frames) I would like to prefetch them and then show them on a webpage as needed.
I have tried several ways of prefetching, including a nifty plugin, but here's a dead simple method:
<div class="animation-container"></div>
<div class="holding-container" style="display:none"></div>
<script>
$('.holding-container').append('<img src="Image1.png" />');
$('.holding-container').append('<img src="Image2.png" />');
</script>
In the Network tab of Firebug or developer tools, I see these calls result in queries to the server, and the images are fetched successfully.
Now, I want to actually use the images. Here's some very simplified code:
$('.animation-container').prepend('<img src="Image1.png"/>');
This is where things go off the rails. The network tabs show the browsers query the server again (receiving 304 NOT MODIFIED). This results in about a 200ms delay before the image is shown. Why does this happen and what can I do about it?