简体   繁体   中英

Preloading img and inserting src into another img without reloading it

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM