是否可以在服务器(IIS)上设置内容过期以强制下载新的脚本文件版本?
发布新的 Web 应用程序后,更新会相当频繁。浏览器会缓存外部脚本和 CSS 文件,更新后,如果用户的浏览器继续使用脚本文件的缓存版本,UI 行为将不会达到应有的效果。
是否可以将服务器设置为发出一次性缓存控制标头,以便任何新请求都会提取从 URL 引用的所有文件的新版本?
如果没有,关于如何有效处理这个问题有什么建议吗?
Having released a new web application, updates are going out fairly frequently. Browsers cache external script and CSS files, and when updated, UI behaviour is not as it should be if the user's browser continues to use a cache version of the script file.
Is it possible to set the server to issue one time cache control headers so that any new requests pull new versions of all files referenced from a URL?
If not, any advice on how to deal with this efficiently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Rails 的方法是在引用文件时将数字附加到文件末尾。您可以在文件末尾附加一个数字,并在新版本中更改该数字
The ways rails does it is by appending a number to the end of the files as they are referenced. You can append a number to the end of the file, and make the number change with a new build
在文件名中添加版本号是确保所有客户端都拥有最新版本的最有效版本。浏览器会将其视为全新文件。
浏览器将根据 HTTP 缓存标头缓存资源。如果它被告知 CSS 文件(例如)在给定时间段内有效,那么它不会在该时间段过去之前尝试重新下载它。这适用于资源级别,因此您无法指示浏览器给定资源实际上已过期,直到浏览器尝试下载该资源为止。
Adding a version number to the file name is the most efficient version of ensuring that all clients has the most recent version. The browser will see it as an all new file.
The browser will cache a resource based on HTTP caching headers. If it is told that a CSS file (for instance) is valid for a given time period, then it will not try to re-download it before that time has passed. This works on a resource level, so you cannot instruct the browser that a given resource has actually expired, until it tries to download it.