清缓存的两种方法:webpack清缓存

1. 浏览器禁止缓存

<meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
  <meta http-equiv="expires" content="0">

元信息解说:https://www.cnblogs.com/jesse131/p/5334311.html

2. webpack 打包js后面添加时间戳,清缓存

webpack.prod.conf.js

const  Version = new Date().getTime();
...
output: {
    path: config.build.assetsRoot,
    filename: utils.assetsPath('js/[name].[chunkhash].'+Version+'.js'),
    chunkFilename: utils.assetsPath('js/[id].[chunkhash].'+Version+'.js')
  },
...

3. vue-cli

vue.config.js   vue-cli打包的时候,内置会给js加上hashchunk,自动清缓存,

下面的配置不能生效,不要自己配了,直接使用内置

const Timestamp=new Date().getTime();
module.exports = {
    configureWebpack: {
    
        output: { // 输出重构  打包编译后的 文件名称  【模块名称.版本号.时间戳】
          filename: `[name].${version}.${Timestamp}.js`,
          chunkFilename: `[name].${version}.${Timestamp}.js`
        }
    },
}

 

posted @ 2020-09-17 15:37  front-gl  阅读(1644)  评论(0编辑  收藏  举报