vue项目npmrunbuild打包项目防止浏览器缓存的操作方法

 

在vue.config.js配置

推荐方法1:

const Timestamp = new Date().getTime()

module.exports = {
  ......
  configureWebpack: config => {
      
          config.output.filename = `js/[name].${Timestamp}.js`
          config.output.chunkFilename = `js/[name].${Timestamp}.js`
      
  },
  ......
  
  css: {
      ......
      extract: {
          filename: `css/[name].${Timestamp}.css`,
          chunkFilename: `css/[name].${Timestamp}.css`
      }
      ......
  }
}

方法2:index.html页面添加

<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache" content="no-cache">

这样添加会导致了用户每次访问你的程序时都要重新请求服务器,所有的静态资源都无法用缓存了,浪费流量,网络压力变大。

关于vue项目 npm run build 打包项目防止浏览器缓存的操作方法的文章就介绍至此,更多相关vue npm run build 打包项目内容请搜索编程宝库以前的文章,希望以后支持编程宝库

制作一个简单的网页倒计时器(js原生代码),供大家参考。实现一个简单的网页倒计时(距离xx年x月x日还剩多少时间),效果是这样的首先HTML代码部分,我们需要简单编写一个html代码,用来接收倒计时时间显示。< ...