[英]How to clean the browser cache, each time a new version of the web application is deployed?
I have a react application and each time a new version is deployed, some users don't get the new version due the browser cache. 我有一个React应用程序,每次部署新版本时,由于浏览器缓存,有些用户无法获得新版本。
Anyone can tell me how to clean the browser cache each time a new version of the software is deployed? 任何人都可以告诉我如何在每次部署新版本的软件时清理浏览器缓存吗?
The cache is a functionality provided by the browser to users. 缓存是浏览器提供给用户的功能。 Because of security reasons, you can not clean the cache using javascript.
由于安全原因,您无法使用javascript清除缓存。
Cleaning cache means you can manipulate physical files from the users' computer and it is a huge security breach if one day you be possible to do that. 清理缓存意味着您可以从用户的计算机上操纵物理文件,如果有一天可以做到这一点,那就是一个巨大的安全漏洞。
Check this answer to reinforce what I'm saying. 检查此答案以加强我的意思。
However, you can tell the browser to never cache your page like this (check this documentation as well): 但是,您可以告诉浏览器永远不要这样缓存您的页面(也请查看此文档):
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
Or change the files known by the browser by associating a hash tag name in all your files (javascript, images, fonts, ...) and change that hash each time you deploy a new version of your software like this: 或通过将所有文件(javascript,图像,字体等)中的哈希标签名称相关联来更改浏览器已知的文件,并在每次部署新版本的软件时更改该哈希,如下所示:
<script src="script.js?version={versionNumber}">
<img src ="imageName.png=version={versionNumber}">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.