清缓存的两种方法: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` } }, }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM