为什么会出现这个问题?
仔细看引用的js 发现更新前后 引用的JS路径是一样的,而js是从服务器上下载本地浏览器的,如果不刷新浏览器缓存。更新后引用JS,CSS,还有一些静态资源还都是浏览器缓存中
注:css,js,html 等都会有相关缓存
问题处理:
1. index.html添meta标签,表示页面不缓存
<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. vue.config.js 配置js,css打包配置,在css,js打包文件添加时间戳,区别版本
const path = require('path')
const Version = new Date().getTime()
const isPro = process.env.NODE_ENV === 'production'
module.exports = {
configureWebpack: {
output: {
filename: `js/[name].${Version}.js`,
chunkFilename: `js/[name].${Version}.js`,
},
},
chainWebpack: (config) => {
if (isPro) {
config.plugin('extract-css').tap((args) => [
{
filename: `css/[name].${Version}.css`,
chunkFilename: `css/[name].${Version}.css`,
},
])
}
},
//....其他配置
}
总结:通过 meta标签设置不缓存,配置css js 打包添加时间戳,通过isPro判断版本打包处理
const isPro = process.env.NODE_ENV === 'production'
if(isPro){
......
}