简体   繁体   English

预加载img并将src插入另一个img中,而无需重新加载它

[英]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. 我正在尝试通过javascript预加载图像,并在适当的时候将其插入另一个图像,而无需进行新的提取。

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. 不幸的是,当我用预加载的src替换img的src时,图像被重新加载,而chrome不使用已兑现的src。 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 在服务器上一切正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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