Vue打包文件放在服务器,浏览器存在缓存问题的解决


在入口文件index.html添加

<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 打包后的文件不能即使更新最新代码。缓存里的内容没有清除。(基本没作用)

解决办法就是在打包的文件名中添加一个版本号以便浏览器能区分。

 

build--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')
  }


免责声明!

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



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