swpp-backends 2.1.3 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  swpp-backends(以下简称 swpp)插件的功能是为网站生成一个高度可用的 ServiceWorker(以下简称 SW),为网站优化二次加载、提供离线体验、提高可靠性,并为此附带了一些其它的功能。
6
6
 
7
- swpp 的全拼为“ServiceWorkerPlusPlus”(或“ServiceWorker++”),但是其与已有的插件“hexo-service-worker”并没有关系,插件中所有代码均为我个人开发,这一点请不要误解。
7
+ swpp 的全拼为“Service Worker Plus Plus”(或“Service Worker++”),但是其与已有的插件“hexo-service-worker”并没有关系,插件中所有代码均为我个人开发,这一点请不要误解。
8
8
 
9
9
  swpp 生成的 SW 与其它插件的对比:
10
10
 
@@ -14,12 +14,13 @@ swpp 生成的 SW 与其它插件的对比:
14
14
  | 缓存增量更新 | ✔️ | ❌ |
15
15
  | 缓存过期时间 | ❌<sup>1</sup> | ✔️ |
16
16
  | 缓存大小限制 | ❌ | ✔️ |
17
- | 预缓存 || ✔️ |
17
+ | 预缓存 | ❌<sup>2</sup> | ✔️ |
18
18
  | Request 篡改 | ✔️ | ❌ |
19
19
  | URL 竞速 | ✔️ | ❌ |
20
20
  | 备用 URL | ✔️ | ❌ |
21
- | 阻塞响应 | ✔️ | ❌ |
21
+ | 204 阻塞响应 | ✔️ | ❌ |
22
22
  | 逃生门 | ✔️ | ❌ |
23
+ | 请求合并 | ✔️ | ❌ |
23
24
  | 跨平台 | ✔️ | ❌ |
24
25
  | 高度自由 | ✔️ | ❌ |
25
26
  | 更新 | 非常频繁 | 超过两年没有更新 |
@@ -30,7 +31,7 @@ swpp 生成的 SW 与其它插件的对比:
30
31
  + ❌:不支持
31
32
 
32
33
  1. 因为有增量更新,所以没提供过期的实现,没必要
33
-
34
+ 2. 预缓存可以在前端实现,SW 实现这个功能容易拖延注册时间
34
35
 
35
36
  目前支持的平台:
36
37
 
@@ -59,7 +59,7 @@ function buildServiceWorker() {
59
59
  url = new URL(request.url)
60
60
  }
61
61
  `).replaceAll('// [modifyRequest else-if]', `
62
- else if (modify) handleFetch(fetch(request).catch(err => new Response(err, {status: -1})))
62
+ else if (modify) handleFetch(fetch(request).catch(err => new Response(err, {status: 499})))
63
63
  `);
64
64
  }
65
65
  if (blockRequest) {
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ const VersionAnalyzer_1 = require("./VersionAnalyzer");
10
10
  const DomBuilder_1 = require("./DomBuilder");
11
11
  // noinspection JSUnusedGlobalSymbols
12
12
  exports.default = {
13
- version: '2.1.3',
13
+ version: '2.1.4',
14
14
  cache: {
15
15
  readEjectData: Utils_1.readEjectData, readUpdateJson: Variant_1.readUpdateJson,
16
16
  readRules: Variant_1.readRules, readMergeVersionMap: Variant_1.readMergeVersionMap,
@@ -12,6 +12,7 @@
12
12
  const dbVersion = {
13
13
  write: (id) => caches.open(CACHE_NAME)
14
14
  .then(cache => cache.put(CTRL_PATH, new Response(JSON.stringify(id)))),
15
+ /** @return {*} */
15
16
  read: () => caches.match(CTRL_PATH).then(response => response?.json())
16
17
  }
17
18
 
@@ -19,16 +20,17 @@
19
20
  self.skipWaiting()
20
21
  const escape = '@$$[escape]'
21
22
  if (escape) {
22
- dbVersion.read().then(oldVersion => {
23
- if (oldVersion && oldVersion.escape !== escape) {
24
- oldVersion.escape = escape
25
- dbVersion.write(oldVersion)
26
- // noinspection JSUnresolvedVariable
27
- caches.delete(CACHE_NAME)
28
- .then(() => clients.matchAll())
29
- .then(list => list.forEach(client => client.postMessage({type: 'escape'})))
30
- }
31
- })
23
+ dbVersion.read()
24
+ .then(async oldVersion => {
25
+ if (oldVersion?.escape !== escape) {
26
+ oldVersion.escape = escape
27
+ await dbVersion.write(oldVersion)
28
+ // noinspection JSUnresolvedVariable
29
+ caches.delete(CACHE_NAME)
30
+ .then(() => clients.matchAll())
31
+ .then(list => list.forEach(client => client.postMessage({type: 'escape'})))
32
+ }
33
+ })
32
34
  }
33
35
  })
34
36
 
@@ -121,7 +123,7 @@
121
123
  const spare = getSpareUrls(request.url)
122
124
  if (spare) handleFetch(fetchFile(request, false, spare))
123
125
  // [modifyRequest else-if]
124
- else handleFetch(fetch(request).catch(err => new Response(err, {status: -1})))
126
+ else handleFetch(fetch(request).catch(err => new Response(err, {status: 499})))
125
127
  }
126
128
  })
127
129
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swpp-backends",
3
- "version": "2.1.3",
3
+ "version": "2.1.6",
4
4
  "main": "dist/index.js",
5
5
  "typings": "types/index.d.ts",
6
6
  "description": "Generate a powerful ServiceWorker for your website.",