如何从浏览器缓存中删除图像 [英] How to remove image from browser cache

查看:276
本文介绍了如何从浏览器缓存中删除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Web应用程序中,我有大量的缩略图,用户可以从原始图像中选择一个缩略图并在客户端进行重新裁剪以重新创建新的缩略图。

In my web app, I have a large collection of thumbnails, the user is able to select a thumbnail and client side recrop from the original image to recreate a new thumbnail.

没关系,在我的应用程序中,我只是将新创建的图像立即设置为图像源,而无需从服务器重新加载,然后将新图像上传到服务器。这是为了确保非常敏感的感觉。问题在于,当用户刷新页面时,他会看到缩略图的缓存旧版本。

That's fine, in my app, I just set the newly created image instantly to the image source, without reloading it from the server, and next to this, the new image is uploaded to the server. This is to ensure a very responsive feeling. The problem is that when to user refreshes the page, he sees the cached old version of the thumbnail.

我知道我可以使用一些image.jpg吗?浏览器必须下载缩略图的新版本,但是正如我说的那样,即使在互联网连接速度慢且速度慢的情况下,该应用也必须具有很高的响应速度。 (这就是为什么应用程序本身存储在用户计算机上,而不是实时下载的原因。只有上载,下载和json正在传输)

I know I could use some image.jpg?sometimestamp to be sure the browser has to download a new version of the thumbnail, but as I said, the app needs to be very responsive, even on small &slow internet connections. (Thats why the app in itself is stored on the user's computer and not downloaded live. Only uploads, downloads and jsons are transitting)

理想的解决方案是能够告诉浏览器:从缓存中删除此特定文件:someurl.com/somefolder/image.jpg,以便浏览器在需要时必须再次获取它。这有可能吗?

The ideal solution would be to be able to tell the browser : remove this particular file from your cache : someurl.com/somefolder/image.jpg, so that the browser has to fetch it again when it needs it. is this possible and how?

所以我不是问如何不缓存文件或如何强制每次调用重新验证,我问的是如何删除

So I'm not asking how not to cache files or how to force re-verification each call, I'm asking how I could remove some particular file from browser's cache.

ps:这可能是仅基于Webkit的解决方案,因为这是它唯一运行的平台。(实际上是一个qtwebkit一个Qt项目。

ps: this can be a webkit-only solution as this is the only platform it is running on.(it is actually a qtwebkit on a Qt project.

推荐答案

函数 window.URL.revokeObjectURL()可以解决您的问题。

The function window.URL.revokeObjectURL() can solve your problem.


URL.revokeObjectURL()静态方法释放现有对象
URL,该URL先前是通过调用
窗口创建的.URL.createObjectURL()在使用对象URL完成
后,请调用此方法,以使浏览器知道它不再需要
来保持对该文件的引用。

The URL.revokeObjectURL() static method releases an existing object URL which was previously created by calling window.URL.createObjectURL(). Call this method when you've finished using a object URL, in order to let the browser know it doesn't need to keep the reference to the file any longer.

有关详细信息: https://developer.m ozilla.org/zh-CN/docs/Web/API/URL.revokeObjectURL

请注意,这是实验函数跨浏览器支持有限。

Note that this is an experimental function with limited cross-browser support.

这篇关于如何从浏览器缓存中删除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆