我怎么没有到期按F5缓存的形象? [英] How do I expire a cached image without hitting F5?

查看:130
本文介绍了我怎么没有到期按F5缓存的形象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与MVC4和C#的Web应用程序。

I am making a web application with MVC4 and C#.

我允许用户上传图片对他们的个人资料图片。在这个时刻,我需要以前的资料图片到期,这样,当浏览器重新加载页面显示的新形象。目前,因为两个图像共享同一名称的浏览器使用已缓存的新形象,而不是以前的形象。

I am allowing the user to upload an image for their profile picture. At this moment, I need the previous profile picture to expire so that when the browser reloads the page the new image is displayed. Currently, since both of the images share the same name the browser uses the previous image that has been cached instead of the new image.

如果我强迫浏览器重新加载F5它显示的新形象。我如何确保返回到他们的个人资料页的用户看到了新的形象,而不是一个在浏览器缓存中没有击中F5?

If I force the browser to reload with F5 it shows the new image. How do I make sure that a user returning to their profile page sees the new image and not the one in the browser cache without hitting F5?

推荐答案

您可以将虚拟参数添加到图像文件名末尾。例如,

You can add a dummy parameter to the end of the image filename. For instance,

<img src="...\avatar.jpg?d=7615833">



,其中数字是随机的或时间戳。它将被忽略,但存在将强制浏览器重新加载图像

where the number is random or a timestamp. It will be ignored, but the presence will force the browser to reload the image.

这篇关于我怎么没有到期按F5缓存的形象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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