It seems that a Google Chrome plugin (Cache Killer) was causing the problem and not the code.
Preload Animated GIFs
-
10-07-2023 - |
Frage
On my page there's an animated GIF displayed like this:
<div>
<a id="image" style="background-image: url('http://example.com/12.gif);"></a>
</div>
When a user clicks, the background image url is switched to random url from a list like this:
<span class="image_url">http://i.imgur.com/qefIaR.gif</span>
<span class="image_url">http://tinypics.com/96683.gif</span>
<span class="image_url">http://imageshost.com/36683.gif</span>
<span class="image_url">http://example.com/wp-content/uploads/funny_carrot.gif</span>
Now the problem is that animated GIFs load pretty slowly, so I thought I'd preload them:
// PRELOAD IMAGES
(function($) {
window.onload = function () {
function preload(preload_img) {
$('<img/>')[0].src = preload_img;
alert(preload_img); // Debug
}
var preload_url;
setTimeout(function(){
$('.image_url').each(function(){
preload_url = $(this).text();
preload(preload_url);
});
}, 3000);
}
}(jQuery));
// END PRELOAD
The GIFs are still loading slow however and I don't notice any difference. Is there any problem with my code or is there a way for me to confirm that it is indeed working?
Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow