前端独立实现页面是否有发布

1、自动更新js (AutoUpdate.js)

javascript 复制代码
import { Modal } from "antd"

let lastSrcs;
const scriptReg = /\<script.*src=["'](?<src>[^"']+)/gm;
async function extractNewScripts() {
    const html = await fetch('/?_timnestamp=' + Date.now()).then(res => {
        return res.text();
    })
    scriptReg.lastIndex = 0;
    let result = [];
    let match;
    console.log(html)
    while ((match = scriptReg.exec(html))) {
        result.push(match.groups.src)
    }
    return result;
}

async function needUpdate() {
    const newScripts = await extractNewScripts();
    if (!lastSrcs) {
        lastSrcs = newScripts
        return false;
    }
    let result = false;
    if (lastSrcs.length !== newScripts.length) {
        result = true;
    }
    for (let i = 0; i < lastSrcs.length; i++) {
        if (lastSrcs[i] !== newScripts[i]) {
            result = true;
            break;
        }
    }
    lastSrcs = newScripts;
    return result
}

const duration = 5000;
function autoRefresh() {
    setTimeout(async () => {
        const willUpdate = await needUpdate();
        if (willUpdate) {
            Modal.success({
                content: '当前系统有更新,请刷新',
                keyboard: false,
                onOk: () => {
                    location.reload(true);
                }
            });
        }
        autoRefresh();
    }, duration)
};
autoRefresh();

2、修改webpack出口打包文件名称

3、引入AutoUpdate.js

javascript 复制代码
import './util/AutoUpdate';
相关推荐
码兄科技2 小时前
Java AI智能体开发实战:从零构建智能对话系统指南
java·开发语言·人工智能
Drone_xjw3 小时前
从 GDB 到 CDB:C/C++ 程序调试的两把“手术刀”
c语言·开发语言·c++
SL-staff4 小时前
智慧园区2000+设备统一管理:JVS-IoT如何降低运维成本40%
java·开发语言·物联网·智慧园区·设备管理·运维优化·jvs-iot
梦帮科技5 小时前
GRAVIS v4.0:基于Web的极速套利架构设计与实时数据流实现
前端·人工智能·rust·自动化·区块链·智能合约·数字货币
爱勇宝5 小时前
办公资料反复修改、补传、交接混乱,我做了个桌面工具来解决这件事
前端·后端·程序员
2zcode5 小时前
基于MATLAB图像处理的饮料瓶灌装液位检测系统设计与实现
开发语言·图像处理·matlab
微信开发api-视频号协议6 小时前
企业微信外部群开发自动化实践过程
java·前端·微信·自动化·企业微信·ipad
甲维斯6 小时前
Fable5:20美金的顶级设计师!
前端·人工智能
kyriewen6 小时前
我同时用了 Claude Code、Cursor 和 Codex,说说三个工具的真实差距——2026 年选错工具比不用 AI 更浪费时间
前端·ai编程·claude
必须得开心呀6 小时前
QT解决中文乱码问题
开发语言·qt