如何强制给定的文件在缓存过期? [英] How do I force a given file to expire in the cache?
问题描述
我有一种感觉,我应该知道这一点。
I have a feeling I should know this.
我有一个包含大量图像的Web应用程序,CSS和脚本文件。
I have a web app that contains a large number of images, css and script files.
我遇到的问题是,如果我更新的应用程序和这些静态的项目之一发生了变化,我需要确保浏览器访问应用程序正在使用的文件的最新版本。
The problem I'm having is that if I update the app and one of these 'static' items has changed, I need to ensure that a browser accessing the app is using the newest version of the file.
我知道我无法从我的应用程序清除客户端缓存,这样出去了。
I know I can't clear the client cache from my app so that's out.
我敢肯定,我不是有过这样的问题,所以我认为我会问这里唯一的家伙。我发现很多东西有关服务器的高速缓存,但没有与此明显的交易。
I'm sure that I'm not the only guy to have had this issue so I thought I'd ask here. I've found lots of stuff about the server cache but nothing that obviously deals with this.
任何人任何指针,我可以跟进?
Anyone any pointers I can follow up?
-
斯图尔特
-- Stuart
推荐答案
在最后使用GET方法来使浏览器认为这是需要更新动态内容。
Use a get method at the end to make the browser think it's dynamic content that need to be updated.
例如
<img src="img.jpg?version=1" />
和只需更改版本
ID每次更改影像的时间。你可能会在CSS和JavaScript的进口,以及使用此功能。
And just change version
id every time you change the image. You might use this in css and javascript imported as well.
这篇关于如何强制给定的文件在缓存过期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!