【发布时间】:2019-12-17 23:33:45
【问题描述】:
更改背景图片时,即使使用 apache mod_expires 模块,这些图片也不会缓存。
更改 apache 的 mod_expires 模块,循环遍历单独 div 中的所有图像,该 div 隐藏在 z-index 后面 1x1px 的某处。
这是我设法缓存图像的方法,并且在关闭浏览器窗口之前它们不会重新加载。 它循环遍历所有图像,创建一个存储在缓存数组中的 HTML 图像节点。 Javascript 的垃圾收集器不会在图像循环后从缓存中删除它们。
const images = ["/img/1.jpg","/img/2.jpg","/img/1.jpg"];
const cache = Array();
for(const path of images){
const img = document.createElement("IMG");
img.src = path;
cache.push(img);
}
是否可以将图像永久缓存在浏览器的缓存中?
【问题讨论】:
-
也许您可以为此使用 cookie。你也可以使用一些 .htaccess 技巧。
标签: javascript css image caching