vue.js

关注公众号 jb51net

关闭
首页 > 网络编程 > JavaScript > javascript类库 > vue.js > vue项目每次更新后清除浏览器缓存

vue项目每次更新后清除浏览器缓存方式

作者:小问号_

本文详细介绍了Vue每次更新后清除浏览器缓存的方法,包括在index.html中添加meta标签不缓存,并在vue.config.js中配置时间戳以区别版本,帮助用户轻松实现页面更新后的缓存清除

vue每次更新后清除浏览器缓存

首先

在index.html中添加meta不缓存

<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.config.js里打包时js

css配置时间戳,区别版本

// 打包时添加时间戳,区别版本
const Version = new Date().getTime();
const isPro = process.env.NODE_ENV === 'production'
configureWebpack: {
    output: {
      filename: `js/[name].${Version}.js`,
      chunkFilename: `js/[name].${Version}.js`,
    },
  },
  //其他代码
chainWebpack: (config) => {
    // 删除 prefetch 选项:  预加载
    config.plugins.delete("prefetch");
    if (isPro) {
      config.plugin('extract-css').tap((args) => [
        {
          filename: `css/[name].${Version}.css`,
          chunkFilename: `css/[name].${Version}.css`,
        },
      ])
    }
    //其他代码
  },

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文