700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 解决vue项目更新版本后浏览器的缓存问题

解决vue项目更新版本后浏览器的缓存问题

时间:2018-09-17 12:55:25

相关推荐

解决vue项目更新版本后浏览器的缓存问题

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。