----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