I have a <img>
placeholder where I want to show images using a slideshow effect:
<img rel="preload" class="home-postcard" src="/img/Rsquare1.jpg" />
I am running this JS script:
var iloop = 0;
window.setInterval(function () {
var dataArray = new Array("/img/Rsquare2.jpg", "/img/Rsquare3.jpg");
$("img.home-postcard").fadeOut("fast", function () {
$(this).attr("rel", "preload");
$(this).attr("src", dataArray[iloop]);
iloop++;
if (iloop === dataArray.length) {
iloop = 0;
}
$(this).fadeIn("slow");
});
}, 10000);
The animation works, but images keep downloading from the network over each iteration and it consumes bandwidth.
I tried to preload the images using rel="preload"
, but they keep downloading each time the src
is rewritten.
What am I missing?
Note: I previously tried this preloading method but images keep downloading whenever the src
attribute is rewritten.
Preloading images with jQuery
Note 2: rel="preload"
is referenced as a potential method: https://developers.google.com/web/updates/2016/03/link-rel-preload