有以下几种思路,可供参考:
1、在入口文件中添加以下代码,提示浏览器该不进行本地缓存。
<meta http-equiv="pragram" content="no-cache">
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="expires" content="0">
2、如果是部署在nginx上,在nginx的配置文件 nginx.config添加:
location = /index.html {
add_header Cache-Control "no-cache, no-store";
}
3、如果是用nginx做反向代理的,这么加
location = /xx(xx为你的代理的项目名) {
add_header Cache-Control "no-cache, no-store";
}
4、还有一种思路,就是在接口请求处做拦截。页面有缓存不刷新,但是接口每次都会请求吧,可以让后台提供一个获取版本号的接口,在项目加载之前访问。每次从接口获取最新的版本号,如果与当前本地缓存的版本号不一致,则说明当前页面是浏览器缓存的,然后强制刷新,同时在本地存入最新的版本号;如果后台返回的版本号与当前本地存的一致,说明当前页面访问的代码就是最新的,无需刷新。