1.3.0 • Published 9 months ago

@terky/update-notifier v1.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

update-notifier是一个用于网站更新时通知用户更新网页内容的插件,支持IE10+,它使用了web workers来发送请求

使用

update-notifier导出了一个函数useNotification,接收以下的参数

namerequiredtypedefaultremark
delaytruenumber180000查询间隔
loopfalsebooleanfalse查询到更新后,是否继续查询
initfalsestring${window.origin}?t=${Date.now()}请求地址
keytruestring要查询的字段
initfalseFetch.init{method: "get"}fetch请求参数,详情

您可以放心,您传入的request函数也会在web worker中执行

例子

搭配webpack

您需要安装html-webpack-plugin,下面详细说明了如何使用

module.exports = {
  ...
  plugins: [
    ...,
    new HtmlWebpackPlugin({
      title: 'title',
      hash: new Data().getTime(),
      template: path.resolve(__dirname, '../index.html')
    })

], ... }

在您的模版文件中
```html
<html>
...
<body data-hash="<%= htmlWebpackPlugin.options.hash %>">
  ...
</body>
</html>

在您项目入口位置

import { useNotification } from '@terky/update-notifier'
...
useNotification({
  key: 'data-hash'
})
...



window.addEventListener('siteUpdate', function({ detail }) {
  if (detail.data) {
    // do something
  }
})
1.3.0

9 months ago

1.2.0

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

1.0.1

1 year ago