1、修改 webpack .prod.conf.js 文件
const version = new Date().getTime();
output: {
path: config.build.assetsRoot,
filename: utils.assetsPath(‘js/[name].[chunkhash:8].’ + version + ‘.js’),
chunkFilename: utils.assetsPath(‘js/[name].[chunkhash:8].’ + version + ‘.js’)
}
2、在 index.html 页面前面加 meta 标签
3、html 页面加载脚本的时候给脚本后面加一个时间戳,修改 webpack.prod.conf.js 文件
new HtmlWebpackPlugin({
filename: config.build.index,
template: ‘index.html’,
inject: true,
hash: version,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
},CommonsChunkPlugin
chunksSortMode: ‘dependency’
}),
4、后端,修改 /conf/nginx.conf 配置文件,让index.html不缓存,同时记得重启nginx
location = /index.html {
add_header Cache-Control “no-cache, no-store”;
}
本文转载:/daheiylx/p/12705090.html