vue项目每次更新后清除浏览器缓存
vue项目每次更新后清除浏览器缓存
·
首先在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">
然后在vue.config.js里打包时js,css配置时间戳,区别版本
// 打包时添加时间戳,区别版本
const Version = new Date().getTime();
const isPro = process.env.NODE_ENV === 'production'
configureWebpack: {
output: {
filename: `js/[name].${Version}.js`,
chunkFilename: `js/[name].${Version}.js`,
},
},
//其他代码
chainWebpack: (config) => {
// 删除 prefetch 选项: 预加载
config.plugins.delete("prefetch");
if (isPro) {
config.plugin('extract-css').tap((args) => [
{
filename: `css/[name].${Version}.css`,
chunkFilename: `css/[name].${Version}.css`,
},
])
}
//其他代码
},
更多推荐
已为社区贡献4条内容
所有评论(0)