@jswork/page-update-checker
v1.0.13
Published
A lightweight, self-contained JavaScript module for real-time webpage update detection and user notification.
Downloads
44
Readme
page-update-checker
A lightweight, self-contained JavaScript module for real-time webpage update detection and user notification.
[!NOTE] The url should be a public accessible url, no cacheable content.
installation
npm install @jswork/page-update-checker
usage
import PageUpdateChecker from '@jswork/page-update-checker';
const checker = PageUpdateChecker.run({
url: 'https://afeiship.github.io/page-update-checker',
interval: 1000 * 60 * 1, // 1 minutes
onUpdateAvailable: () => {
const confirmed = window.confirm('网页内容已经更新,你是否现在刷新?');
if (confirmed) {
window.location.reload();
} else {
this.ignore();
}
}
});
// trigger ingore events;
window.dispatchEvent(new CustomEvent('@:page-update-checker:ignore'));
// use nx
nx.rootDispatch('@:page-update-checker:ignore');
license
Code released under the MIT license.