How do I force a given file to expire in the cache?

无人久伴 提交于 2019-12-11 06:09:21

问题


I have a feeling I should know this.

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


回答1:


Use a get method at the end to make the browser think it's dynamic content that need to be updated.

For example

<img src="img.jpg?version=1" />

And just change version id every time you change the image. You might use this in css and javascript imported as well.



来源:https://stackoverflow.com/questions/8443441/how-do-i-force-a-given-file-to-expire-in-the-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!