vue解决部署文件缓存方式

问题:系统上线后,除了bug。紧急修复后,发现安卓正常,ios上海市有问题。通过debug后发现,ios上缓存严重。于是想到了打包文件加时间戳的方式来去除缓存。
vue2 配置打包输出文件名方式:

const baseUrl = "./"
const timestr = new Date().getTime()
module.exports = {
   
    outputDir: "delixi",
    publicPath: baseUrl, // 根据你的实际情况更改这里
    // 选项...
    lintOnSave: false,
    productionSourceMap: false,
    devServer: {
   
        port: 8080,
        overlay: {
   
            warnings: true,
            errors: true
        }
    },
    filenameHashing: false,
    configureWebpack: {
   
        performance: {
   hints: false},
        output: {
   
            filename: `js/js[name].${
     timestr}.js`,
            chunkFilename: `js/chunk.[id].${
     timestr}.js`,
        }
    },
    css: {
   
        extract: {
   
            filename: `css/[name].${
     timestr}.css`,
            chunkFilename: `css/chunk.[id].${
     timestr}.css`,
        }
    }

}

附:vite配置打包文件名称加时间戳方式

import {
    resolve } from 'path';
import {
    defineConfig, loadEnv } from 'vite';
import vue2 from '@vitejs/plugin-vue2';
const Timestamp = new Date().getTime();//随机时间戳
export default ({
     mode }) => {
   
  const {
    VITE_PORT, VITE_BASE_URL, VITE_PROXY_DOMAIN_REAL } = loadEnv(mode, process.cwd());

  return defineConfig({
   
    base: VITE_BASE_URL,
    plugins: [vue2()],
    resolve: {
   
      alias: {
   
        '@': resolve(__dirname, 'src'),
      },
    },
    css: {
   
      preprocessorOptions: {
   
        less: {
   
          modifyVars: {
   
            hack: `true; @import (reference) "${
     resolve('src/style/variables.less')}";`,
          },
          math: 'strict',
          javascriptEnabled: true,
        },
      },
    },
    server: {
   
      // 是否开启 https
      https: false,
      // 端口号
      port: VITE_PORT,
      // 监听所有地址
      host: '0.0.0.0',
      // 服务启动时是否自动打开浏览器
      open: false,
      // 允许跨域
      cors: true,
      // 自定义代理规则
      proxy: {
   
        '/admin': {
   
          target: VITE_PROXY_DOMAIN_REAL,
          ws: true,
          changeOrigin: true,
          // rewrite: (path) => path.replace(/^\/admin/, ''),
        },
        '/master': {
   
          target: VITE_PROXY_DOMAIN_REAL,
          ws: true,
          changeOrigin: true,
          // rewrite: (path) => path.replace(/^\/admin/, ''),
        },
      },
    },
    build: {
   
      outDir: 'delixi',
      // publicPath: './',
      // 设置最终构建的浏览器兼容目标
      target: 'es2015',
      // 构建后是否生成 source map 文件
      sourcemap: false,
      //  chunk 大小警告的限制(以 kbs 为单位)
      // chunkSizeWarningLimit: 2000,
      // 启用/禁用 gzip 压缩大小报告
      reportCompressedSize: false,
      rollupOptions: {
   
        output: {
   
          chunkFileNames: `static/js/[name].[hash]${
     Timestamp}.js`,
          entryFileNames: `static/js/[name].[hash]${
     Timestamp}.js`,
          assetFileNames: `static/[ext]/[name].[hash]${
     Timestamp}.[ext]`,
        },
      }
    },
  });
};

这次h5活动遇到的大坑:
1、使用vite做的h5项目,在ios上缓存刷新不掉,或者很久才能刷新掉。打包文件加时间戳,部分手机也无效
2、iOS上,点击事件有时候会失效。或者是路由跳转不过去。同一个手机有时候会发剩,有时候正常。最终重构项目,不使用vite。没有再发生类似问题。。。

推荐:好用的230G电话卡

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-01-20 10:52:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-20 10:52:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-20 10:52:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-20 10:52:02       20 阅读

热门阅读

  1. 「HDLBits题解」Counters

    2024-01-20 10:52:02       35 阅读
  2. 服务器防火墙有哪些用处

    2024-01-20 10:52:02       36 阅读
  3. vue3使用element-plus 树组件(el-tree)数据回显

    2024-01-20 10:52:02       29 阅读
  4. 【洛谷 P2084】进制转换 题解(模拟+字符串)

    2024-01-20 10:52:02       32 阅读
  5. RPA与ChatGPT的融合:智能化流程的未来

    2024-01-20 10:52:02       25 阅读
  6. 地府网站火热开发中。。。

    2024-01-20 10:52:02       37 阅读
  7. 医疗行业的舆情监测

    2024-01-20 10:52:02       42 阅读
  8. 解决iCloud备份灰显问题的有效方法

    2024-01-20 10:52:02       36 阅读
  9. 零知识学习ACPI —— 1. 初识

    2024-01-20 10:52:02       35 阅读