0
votes

I'm trying to preload an image via javascript and insert it into another image at the right moment without a new fetch.

Unfortuantely, when I replace the src of an img with the preloaded src, the image gets reloaded and chrome doesn't use the cashed one. What can I do?

This is how I preload the image:

if (document.images) {
    this.img = new Image();
    this.img.src = "img/img.jpg";
}

and later I'm inserting it like this:

this.poster.src = this.img.src;

Thanks!

1
Is your image source file name the same with the preloaded and fetched images? If so, that is your issue. To bust caching and force the image change, your filename needs to be different so that the browser goes out and grabs the new image. ā€“ Korgrue
No, Iā€™d like to cache the image and insert it without reloading it ā€“ vinni

1 Answers

0
votes

Actually this code works fine. I was using a preprocessor that would prohibit caching. On the server everything works fine