- 🤔 编写高质量、可维护、易扩展的程序代码
- ✨ 开发3步走,测试->编码->重构
joeshutt / version-polling Goto Github PK
View Code? Open in Web Editor NEW一个用于实时检测 web 应用更新的 JavaScript 库
License: MIT License
一个用于实时检测 web 应用更新的 JavaScript 库
License: MIT License
在应用入口文件中代码如下:
import { createVersionPolling } from 'version-polling'
import { Button, notification, Space } from 'antd'
createVersionPolling({
appETagKey: '__APP_ETAG__',
pollingInterval: 5 * 1000, // 单位为毫秒
silent: process.env.NODE_ENV === 'development', // 开发环境下不检测
onUpdate: (self) => {
notification.info({
message: '页面有新的功能更新,请您点击确定按钮刷新查看~',
btn: (
<Space>
<Button
size="small"
onClick={() => {
notification.destroy()
self.onCancel()
}}
>
取消
</Button>
<Button
type="primary"
size="small"
onClick={() => {
notification.destroy()
self.onRefresh()
}}
>
确认
</Button>
</Space>
),
})
},
})
页面报错内容:
Uncaught Error: Module parse failed: Unexpected token (278:35)
You may need an appropriate loader to handle this file type.
| _this.stop();
|
> _this.options.onUpdate?.(_this);
| }
| };
at ./node_modules/.pnpm/[email protected]/node_modules/version-polling/dist/version-polling.js (value-equal.js:29:1)
at __webpack_require__ (bootstrap:786:1)
at fn (bootstrap:149:1)
at Module.<anonymous> (index.css:45:1)
at ./src/index.tsx (index.tsx:70:1)
at __webpack_require__ (bootstrap:786:1)
at fn (bootstrap:149:1)
at 0 (utils.tsx:734:1)
at __webpack_require__ (bootstrap:786:1)
at checkDeferredModules (bootstrap:45:1)
at Array.webpackJsonpCall
package.json 文件:
"react": "^17.0.1",
"webpack": "4.29.6",
"node": "v16.20.2",
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.
查看源码如下:
onRefresh() {
window.location.reload();
}
window.location.reload();方法相当于浏览器正常刷新,如果出现重新打包的情况,还是会使用原来的缓存文件。使用window.location.reload(true);会不会好点,相当于清空缓存的刷新
现在遇到两个问题:
1.页面不可见后,任务停止,页面恢复后会立即只执行一次,但是不会实时去执行了。
2.index.html 没有更新内容,但是等待 1 分钟左右,依然弹窗更新。
对于 Vue 这种SPA 单页应用。htmlFileUrl: ${location.origin}
,是否是需要这样配置?
https://github.com/JoeshuTT/version-polling/blob/main/src/utils/index.ts#L40C33-L40C33
假定此时正在发版或者其它的操作,导致htmlFileUrl 不可访问,此时,从 const etag = response.headers.get("etag");
中得到etag 为 null,与lastEtag 不等,会触发onUpdate回调
export 'createVersionPolling' (imported as 'createVersionPolling') was not found in 'version-polling'
在pollingInterval字段里设置时长为 60 * 60 * 1000的间隔时间,当发布新版本时会立刻发现版本更新,是我的时间设置问题还是一直在每秒进行轮询
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.