vue项目,代码部署之后,如何解决浏览器存在缓存问题
1.在index.html头部添加如下代码:
<meta http-equiv="pragram" content="no-cache">
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">
2.在vue.config.js中添加如下代码:
const Timestamp = new Date().getTime();
module.exports = {
configureWebpack: { // webpack 配置
output: { // 输出重构 打包编译后的 文件名称 【模块名称.版本号.时间戳】
filename: `static/js/[name].${process.env.VUE_APP_Version}.${Timestamp}.js`,
chunkFilename: `static/js/[name].${process.env.VUE_APP_Version}.${Timestamp}.js`
},
},
...
}
3.在nginx.conf页面添加如下代码:
location = /index.html {
add_header Cache-Control "no-cache, no-store";
}