简体   繁体   English

每次部署新版本的Web应用程序时,如何清理浏览器缓存?

[英]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.

相关问题 使用 Service Worker 反应应用程序 - 在新版本上强制更新浏览器缓存 - React application with Service Worker - Force update of browser cache on new version 使用JavaScript开发时,Web浏览器缓存保持干净 - Web browser cache clean while javascript development 在我的Web应用程序上模拟浏览器缓存 - simulating browser cache on my web application 如何在每次播放视频时在浏览器上缓存视频并使用缓存的版本 - How to cache the video on the browser and used the cached version every time the video is played 每次用户在新的浏览器窗口中访问应用程序URL时,如何以编程方式在IE中创建新的浏览器会话 - How to programmatically create new browser sessions in IE every time a user accessed an application URL in new browser window 处理新版本的AngularJS Web应用程序 - Handle new version AngularJS web application 如何在MVC应用程序中清除浏览器缓存? - How to clear browser cache in MVC application? 新部署,在第一次加载页面时清除浏览器缓存 - New deployment, have browser cache cleared the first time the page is loaded Web浏览器缓存问题 - Web browser cache issue 自动javascript版本控制以避免浏览器缓存清理 - automatic javascript versioning to avoid browser cache clean
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM