{"id":90010,"date":"2026-08-04T14:08:34","date_gmt":"2026-08-04T06:08:34","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/90010.html"},"modified":"2026-08-04T14:08:34","modified_gmt":"2026-08-04T06:08:34","slug":"%e5%89%8d%e7%ab%af%e5%ba%94%e7%94%a8%e7%a6%bb%e7%ba%bf%e6%9a%82%e5%81%9c%e6%9b%b4%e6%96%b0%e7%ad%96%e7%95%a5%e6%8a%80%e6%9c%af%e6%96%87%e6%a1%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/90010.html","title":{"rendered":"\u524d\u7aef\u5e94\u7528\u79bb\u7ebf\u6682\u505c\u66f4\u65b0\u7b56\u7565\u6280\u672f\u6587\u6863"},"content":{"rendered":"<\/p>\n<p>&gt; \u7248\u672c&#xff1a;v1.0 &#xff5c; \u9002\u7528\u8303\u56f4&#xff1a;PWA \/ SPA \/ \u684c\u9762\u7aef&#xff08;Electron\u3001Tauri \u7b49&#xff09;\u53ca\u79fb\u52a8\u7aef Hybrid \u524d\u7aef\u5e94\u7528 &gt; \u5173\u952e\u8bcd&#xff1a;\u79bb\u7ebf\u4f18\u5148&#xff08;Offline-First&#xff09;\u3001\u66f4\u65b0\u6682\u505c\u3001\u65ad\u70b9\u7eed\u4f20\u3001\u51b2\u7a81\u89e3\u51b3\u3001Service Worker\u3001\u672c\u5730\u961f\u5217<\/p>\n<p>&#8212;<\/p>\n<p>## 1. \u80cc\u666f\u4e0e\u95ee\u9898\u5b9a\u4e49<\/p>\n<p>\u73b0\u4ee3\u524d\u7aef\u5e94\u7528\u8d8a\u6765\u8d8a\u591a\u5730\u8fd0\u884c\u5728\u5f31\u7f51\u6216\u65ad\u7f51\u73af\u5883&#xff08;\u5730\u94c1\u3001\u7535\u68af\u3001\u8de8\u56fd\u5dee\u65c5\u3001\u5de5\u4e1a\u73b0\u573a\u7b49&#xff09;\u3002\u5728\u8fd9\u4e9b\u573a\u666f\u4e0b&#xff0c;\u7528\u6237\u5bf9&#034;\u5e94\u7528\u80fd\u7528&#034;\u7684\u9884\u671f\u9ad8\u4e8e&#034;\u6570\u636e\u548c\u4e91\u7aef\u5b9e\u65f6\u540c\u6b65&#034;\u3002\u5982\u679c\u66f4\u65b0\u903b\u8f91\u4e0d\u505a\u7279\u6b8a\u5904\u7406&#xff0c;\u4f1a\u66b4\u9732\u51fa\u4e09\u7c7b\u5178\u578b\u95ee\u9898&#xff1a;<\/p>\n<p>1. **\u5199\u64cd\u4f5c\u4e22\u5931**&#xff1a;\u7528\u6237\u79bb\u7ebf\u65f6\u63d0\u4ea4\u7684\u8868\u5355\u3001\u8349\u7a3f\u3001\u72b6\u6001\u53d8\u66f4&#xff0c;\u56e0\u8bf7\u6c42\u5931\u8d25\u800c\u88ab\u76f4\u63a5\u4e22\u5f03\u6216\u629b\u51fa\u9519\u8bef&#xff0c;\u9020\u6210\u6570\u636e\u4e22\u5931\u4e0e\u4f53\u9a8c\u65ad\u88c2\u3002 2. **\u66f4\u65b0\u98ce\u66b4**&#xff1a;\u5e94\u7528\u91cd\u8fde\u540e&#xff0c;\u5806\u79ef\u7684\u66f4\u65b0\u8bf7\u6c42\u672a\u7ecf\u7f16\u6392\u5730\u5e76\u53d1\u53d1\u51fa&#xff0c;\u77ac\u95f4\u6253\u7206\u540e\u7aef&#xff0c;\u5f15\u53d1\u9650\u6d41\u3001\u96ea\u5d29\u6216\u91cd\u590d\u5199\u5165\u3002 3. **\u7248\u672c\u9519\u4e71**&#xff1a;PWA \u7684 Service Worker \u5728\u79bb\u7ebf\u65f6\u5c1d\u8bd5\u6fc0\u6d3b\u65b0\u7248\u672c&#xff0c;\u53ef\u80fd\u5bfc\u81f4\u8d44\u6e90\u52a0\u8f7d\u4e0d\u5168\u3001\u767d\u5c4f\u6216\u8fd0\u884c\u6001\u4e0d\u4e00\u81f4\u3002<\/p>\n<p>**\u79bb\u7ebf\u6682\u505c\u66f4\u65b0\u7b56\u7565&#xff08;Offline Pause-and-Resume Update Strategy&#xff09;** \u7684\u6838\u5fc3\u76ee\u6807&#xff1a;\u5728\u7f51\u7edc\u4e0d\u53ef\u7528\u65f6&#xff0c;**\u5b89\u5168\u3001\u6709\u5e8f\u5730\u6682\u505c\u6240\u6709&#034;\u9700\u8981\u4e0a\u4e91&#034;\u7684\u66f4\u65b0**&#xff0c;\u5c06\u5176\u6301\u4e45\u5316\u5230\u672c\u5730&#xff1b;\u5728\u7f51\u7edc\u6062\u590d\u540e&#xff0c;**\u6309\u53ef\u63a7\u8282\u594f\u7eed\u4f20**\u8fd9\u4e9b\u66f4\u65b0&#xff0c;\u5e76\u5bf9\u53ef\u80fd\u51fa\u73b0\u7684\u51b2\u7a81\u505a\u53ef\u9884\u6d4b\u7684\u5904\u7406\u3002<\/p>\n<p>&#8212;<\/p>\n<p>## 2. \u66f4\u65b0\u7c7b\u578b\u7684\u5206\u5c42<\/p>\n<p>\u5e76\u975e\u6240\u6709&#034;\u66f4\u65b0&#034;\u90fd\u5e94\u4ee5\u540c\u4e00\u79cd\u65b9\u5f0f\u5904\u7406\u3002\u5efa\u8bae\u6309\u4ee5\u4e0b\u4e09\u5c42\u5206\u7c7b&#xff0c;\u5206\u522b\u5236\u5b9a\u6682\u505c\/\u6062\u590d\u7b56\u7565&#xff1a;<\/p>\n<p>| \u5c42\u7ea7 | \u66f4\u65b0\u7c7b\u578b | \u65b9\u5411 | \u79bb\u7ebf\u5904\u7406 | \u5178\u578b\u624b\u6bb5 | |&#8212;&#8212;|&#8212;&#8212;&#8212;-|&#8212;&#8212;|&#8212;&#8212;&#8212;-|&#8212;&#8212;&#8212;-| | L1 | \u5e94\u7528\u672c\u4f53\u7248\u672c\u66f4\u65b0&#xff08;SW \/ \u8d44\u6e90\u5305&#xff09; | \u4e91\u7aef \u2192 \u5ba2\u6237\u7aef | \u6682\u505c\u6fc0\u6d3b&#xff0c;\u63d0\u793a\u7528\u6237 | Service Worker \u751f\u547d\u5468\u671f\u7ba1\u7406 | | L2 | \u7528\u6237\u5199\u64cd\u4f5c&#xff08;\u4e1a\u52a1\u6570\u636e\u53d8\u66f4&#xff09; | \u5ba2\u6237\u7aef \u2192 \u4e91\u7aef | \u5165\u961f\u6301\u4e45\u5316&#xff0c;\u6682\u505c\u63d0\u4ea4 | \u672c\u5730\u4efb\u52a1\u961f\u5217 &#043; IndexedDB | | L3 | \u589e\u91cf\u6570\u636e\u62c9\u53d6&#xff08;\u914d\u7f6e\u3001\u6d88\u606f\u3001\u5217\u8868&#xff09; | \u4e91\u7aef \u2192 \u5ba2\u6237\u7aef | \u6682\u505c\u62c9\u53d6&#xff0c;\u6807\u8bb0\u810f | \u589e\u91cf\u6e38\u6807 &#043; \u91cd\u8fde\u56de\u6e90 |<\/p>\n<p>&gt; \u672c\u6587\u91cd\u70b9\u8986\u76d6 **L1&#xff08;\u7248\u672c\u6682\u505c&#xff09;** \u4e0e **L2&#xff08;\u5199\u64cd\u4f5c\u961f\u5217\u5316&#xff09;**&#xff0c;\u8fd9\u662f\u79bb\u7ebf\u7b56\u7565\u4e2d\u6700\u5173\u952e\u3001\u6700\u6613\u51fa\u9519\u7684\u4e24\u5c42\u3002<\/p>\n<p>&#8212;<\/p>\n<p>## 3. \u6574\u4f53\u67b6\u6784<\/p>\n<p>&#096;&#096;&#096; \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u5e94\u7528 UI \u5c42 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u2502 \u2502 \u00a0 \u7528\u6237\u64cd\u4f5c \u2192 \u4ea7\u751f Update \u4e8b\u4ef6 \u2192 \u8c03\u7528 UpdateScheduler \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u25bc \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u7f51\u7edc\u72b6\u6001\u611f\u77e5 (NetworkMonitor) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u2502 \u2502 \u00a0 online \/ offline \u4e8b\u4ef6 &#043; \u5fc3\u8df3\u63a2\u6d4b(HTTP Ping \/ WebSocket) \u00a0 \u00a0 \u00a0\u2502 \u2502 \u00a0 \u5bf9\u5916\u66b4\u9732&#xff1a;isOnline\u3001onChange\u3001quality(\u5f31\u7f51\/\u6b63\u5e38) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u5728\u7ebf \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u2502 \u79bb\u7ebf \u00a0 \u00a0 \u00a0 \u00a0 \u25bc \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u25bc \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u00a0\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 \u76f4\u63a5\u63d0\u4ea4\u8fdc\u7aef \u00a0\u2502 \u00a0\u2502 \u00a0 \u00a0 \u00a0 UpdateQueue&#xff08;\u6301\u4e45\u5316\u4efb\u52a1\u961f\u5217&#xff09; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u2502 \u2502 (HTTP\/Push) \u00a0\u2502 \u00a0\u2502 \u00a0IndexedDB: {id, payload, meta, status} \u00a0 \u00a0 \u00a0\u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u00a0\u2502 \u00a0&#8211; enqueue: \u5199\u5165 pending \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0&#8211; pause: \u72b6\u6001\u673a\u6302\u8d77 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0&#8211; resume: \u6309\u5e8f flush \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u7f51\u7edc\u6062\u590d\u65f6\u89e6\u53d1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u25bc \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0 Flush Controller&#xff08;\u7eed\u4f20\u7f16\u6392\u5668&#xff09; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0 &#8211; \u5e76\u53d1\u5ea6\u63a7\u5236 \/ \u9650\u901f \/ \u9000\u907f\u91cd\u8bd5 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0 &#8211; \u51b2\u7a81\u68c0\u6d4b&#xff08;\u7248\u672c\u53f7 \/ \u65f6\u95f4\u6233 \/ CRDT&#xff09; \u00a0 \u00a0 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0 &#8211; \u5931\u8d25\u56de\u6eda\u4e0e\u6b7b\u4fe1\u961f\u5217&#xff08;DLQ&#xff09; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 &#096;&#096;&#096;<\/p>\n<p>&#8212;<\/p>\n<p>## 4. \u5173\u952e\u7b56\u7565\u8be6\u89e3<\/p>\n<p>### 4.1 \u7f51\u7edc\u72b6\u6001\u611f\u77e5&#xff08;\u4e0d\u8981\u53ea\u4fe1 &#096;navigator.onLine&#096;&#xff09;<\/p>\n<p>&#096;navigator.onLine&#096; \u4e0e &#096;online\/offline&#096; \u4e8b\u4ef6**\u4e0d\u53ef\u9760**&#xff1a;\u5b83\u53ea\u53cd\u6620&#034;\u662f\u5426\u6709\u7f51\u7edc\u63a5\u53e3&#034;&#xff0c;\u4e0d\u53cd\u6620&#034;\u662f\u5426\u80fd\u771f\u6b63\u8bbf\u95ee\u4e1a\u52a1\u540e\u7aef&#034;\u3002\u5fc5\u987b\u53e0\u52a0\u4e3b\u52a8\u63a2\u6d4b\u3002<\/p>\n<p>&#096;&#096;&#096;ts class NetworkMonitor { \u00a0 private online &#061; navigator.onLine; \u00a0 private listeners &#061; new Set&lt;(online: boolean) &#061;&gt; void&gt;(); \u00a0 private timer?: number;<\/p>\n<p>\u00a0 constructor(private pingUrl &#061; &#039;\/api\/__health&#039;) { \u00a0 \u00a0 window.addEventListener(&#039;online&#039;, () &#061;&gt; this.probe()); \u00a0 \u00a0 window.addEventListener(&#039;offline&#039;, () &#061;&gt; this.set(false)); \u00a0 \u00a0 this.probe(); \u00a0 \u00a0 this.timer &#061; window.setInterval(() &#061;&gt; this.probe(), 15_000); \u00a0 }<\/p>\n<p>\u00a0 get isOnline() { return this.online; }<\/p>\n<p>\u00a0 onChange(fn: (online: boolean) &#061;&gt; void) { \u00a0 \u00a0 this.listeners.add(fn); \u00a0 \u00a0 return () &#061;&gt; this.listeners.delete(fn); \u00a0 }<\/p>\n<p>\u00a0 \/** \u7528\u5e26\u8d85\u65f6\u7684\u8bf7\u6c42\u786e\u8ba4&#034;\u771f\u53ef\u8fbe&#034;&#xff0c;\u800c\u975e\u4ec5\u770b\u7f51\u5361 *\/ \u00a0 private async probe() { \u00a0 \u00a0 if (!navigator.onLine) return this.set(false); \u00a0 \u00a0 try { \u00a0 \u00a0 \u00a0 const ctrl &#061; new AbortController(); \u00a0 \u00a0 \u00a0 const t &#061; setTimeout(() &#061;&gt; ctrl.abort(), 3000); \u00a0 \u00a0 \u00a0 await fetch(this.pingUrl, { method: &#039;HEAD&#039;, cache: &#039;no-store&#039;, signal: ctrl.signal }); \u00a0 \u00a0 \u00a0 clearTimeout(t); \u00a0 \u00a0 \u00a0 this.set(true); \u00a0 \u00a0 } catch { \u00a0 \u00a0 \u00a0 this.set(false); \u00a0 \u00a0 } \u00a0 }<\/p>\n<p>\u00a0 private set(v: boolean) { \u00a0 \u00a0 if (this.online &#061;&#061;&#061; v) return; \u00a0 \u00a0 this.online &#061; v; \u00a0 \u00a0 this.listeners.forEach(fn &#061;&gt; fn(v)); \u00a0 } } &#096;&#096;&#096;<\/p>\n<p>&gt; \u8fdb\u9636&#xff1a;\u53ef\u7528\u6027 &#096;Network Information API&#096;&#xff08;&#096;navigator.connection.effectiveType&#096;&#xff09;\u8bc6\u522b\u5f31\u7f51&#xff08;2g\/slow-2g&#xff09;&#xff0c;\u5728\u5f31\u7f51\u4e0b\u540c\u6837\u8fdb\u5165&#034;\u51c6\u79bb\u7ebf&#034;\u8282\u6d41\u6a21\u5f0f\u3002<\/p>\n<p>### 4.2 L1&#xff1a;\u5e94\u7528\u7248\u672c\u66f4\u65b0\u7684\u79bb\u7ebf\u6682\u505c<\/p>\n<p>PWA \u4e2d Service Worker \u6ce8\u518c\u65b0\u7248\u672c\u65f6&#xff0c;\u9ed8\u8ba4\u4f1a\u5728\u9875\u9762\u4e0b\u6b21\u52a0\u8f7d\u65f6\u6fc0\u6d3b\u3002\u82e5\u7528\u6237**\u79bb\u7ebf\u65f6**SW \u5df2\u7ecf\u5728\u540e\u53f0\u5b89\u88c5\u5b8c\u65b0\u7248\u672c&#xff0c;\u76f4\u63a5 &#096;skipWaiting()&#096; &#043; &#096;clients.claim()&#096; \u53ef\u80fd\u8ba9\u9875\u9762\u5728\u62ff\u4e0d\u5230\u65b0\u8d44\u6e90\u7684\u60c5\u51b5\u4e0b\u8fd0\u884c&#xff0c;\u5bfc\u81f4\u767d\u5c4f\u3002<\/p>\n<p>**\u63a8\u8350\u7b56\u7565&#xff1a;\u79bb\u7ebf\u65f6\u6682\u505c\u6fc0\u6d3b&#xff0c;\u8054\u7f51\u540e\u518d\u63d0\u793a\u5237\u65b0\u3002**<\/p>\n<p>&#096;&#096;&#096;ts \/\/ sw.js let pendingActivation &#061; false; self.addEventListener(&#039;install&#039;, (e) &#061;&gt; { \u00a0 \/\/ \u4e0d\u7acb\u5373 skipWaiting&#xff0c;\u7b49\u5f85\u63a7\u5236\u5668\u547d\u4ee4 \u00a0 self.skipWaiting(); \/\/ \u4ec5\u5f53\u5728\u7ebf\u4e14\u7528\u6237\u786e\u8ba4\u65f6 }); self.addEventListener(&#039;message&#039;, (e) &#061;&gt; { \u00a0 if (e.data &#061;&#061;&#061; &#039;SKIP_WAITING&#039;) self.skipWaiting(); }); &#096;&#096;&#096;<\/p>\n<p>&#096;&#096;&#096;ts \/\/ \u4e3b\u7ebf\u7a0b&#xff1a;\u914d\u5408\u7f51\u7edc\u72b6\u6001\u51b3\u5b9a\u662f\u5426\u5141\u8bb8\u6fc0\u6d3b const reg &#061; await navigator.serviceWorker.ready; reg.addEventListener(&#039;updatefound&#039;, () &#061;&gt; { \u00a0 const newWorker &#061; reg.installing!; \u00a0 newWorker.addEventListener(&#039;statechange&#039;, () &#061;&gt; { \u00a0 \u00a0 if (newWorker.state &#061;&#061;&#061; &#039;installed&#039; &amp;&amp; navigator.serviceWorker.controller) { \u00a0 \u00a0 \u00a0 const hasUpdate &#061; true; \u00a0 \u00a0 \u00a0 if (networkMonitor.isOnline) { \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u5728\u7ebf&#xff1a;\u63d0\u793a\u7528\u6237\u5237\u65b0\u4ee5\u5e94\u7528\u66f4\u65b0 \u00a0 \u00a0 \u00a0 \u00a0 showUpdateToast(() &#061;&gt; newWorker.postMessage(&#039;SKIP_WAITING&#039;)); \u00a0 \u00a0 \u00a0 } else { \u00a0 \u00a0 \u00a0 \u00a0 \/\/ \u79bb\u7ebf&#xff1a;\u6682\u505c\u66f4\u65b0&#xff0c;\u8054\u7f51\u540e\u518d\u5524\u9192 \u00a0 \u00a0 \u00a0 \u00a0 networkMonitor.onChange((online) &#061;&gt; { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (online) showUpdateToast(() &#061;&gt; newWorker.postMessage(&#039;SKIP_WAITING&#039;)); \u00a0 \u00a0 \u00a0 \u00a0 }); \u00a0 \u00a0 \u00a0 } \u00a0 \u00a0 } \u00a0 }); }); &#096;&#096;&#096;<\/p>\n<p>**\u8981\u70b9**&#xff1a; &#8211; \u79bb\u7ebf\u65f6**\u4e0d\u8981**\u81ea\u52a8 &#096;skipWaiting()&#096;&#xff0c;\u907f\u514d\u8fd0\u884c\u6001\u4e0e\u8d44\u6e90\u7248\u672c\u4e0d\u5339\u914d\u3002 &#8211; \u8054\u7f51\u540e\u7528 Toast\/\u5f39\u7a97\u8ba9\u7528\u6237\u4e3b\u52a8\u89e6\u53d1\u5237\u65b0&#xff0c;\u4fdd\u8bc1\u66f4\u65b0\u53d1\u751f\u5728\u53ef\u9884\u671f\u65f6\u523b\u3002<\/p>\n<p>### 4.3 L2&#xff1a;\u5199\u64cd\u4f5c\u961f\u5217\u5316&#xff08;\u6838\u5fc3&#xff09;<\/p>\n<p>\u6240\u6709&#034;\u9700\u8981\u4e0a\u4e91&#034;\u7684\u7528\u6237\u66f4\u65b0&#xff0c;\u79bb\u7ebf\u65f6\u4e0d\u5e94\u76f4\u63a5 &#096;fetch&#096;\u3002\u7edf\u4e00\u8d70 &#096;UpdateScheduler&#096;&#xff1a;<\/p>\n<p>&#8211; \u5728\u7ebf \u2192 \u76f4\u63a5\u63d0\u4ea4&#xff1b; &#8211; \u79bb\u7ebf \u2192 \u5199\u5165 IndexedDB \u961f\u5217&#xff0c;\u72b6\u6001\u7f6e &#096;pending&#096;&#xff0c;UI \u7acb\u5373\u53cd\u9988&#034;\u5df2\u4fdd\u5b58&#xff08;\u5f85\u540c\u6b65&#xff09;&#034;\u3002<\/p>\n<p>&#096;&#096;&#096;ts \/\/ \u4f7f\u7528 idb-keyval \u6f14\u793a&#xff1b;\u751f\u4ea7\u5efa\u8bae\u7528\u66f4\u5b8c\u6574\u7684\u961f\u5217\u5e93\u6216\u81ea\u7814 import { set, get, del, keys } from &#039;idb-keyval&#039;;<\/p>\n<p>interface UpdateTask { \u00a0 id: string; \u00a0 type: string; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ \u5982 &#039;order.update&#039; \u00a0 payload: unknown; \u00a0 meta: { baseVersion?: number; createdAt: number; retry: number }; \u00a0 status: &#039;pending&#039; | &#039;inflight&#039; | &#039;done&#039; | &#039;dead&#039;; }<\/p>\n<p>const QUEUE_PREFIX &#061; &#039;uq:&#039;; const enqueue &#061; (task: UpdateTask) &#061;&gt; set(QUEUE_PREFIX &#043; task.id, task); const allPending &#061; async () &#061;&gt; (await keys()) \u00a0 .filter(k &#061;&gt; String(k).startsWith(QUEUE_PREFIX)) \u00a0 .map(k &#061;&gt; get(k)); &#096;&#096;&#096;<\/p>\n<p>UI \u4fa7\u53cd\u9988&#xff1a;<\/p>\n<p>&#096;&#096;&#096;ts async function submitUpdate(task: UpdateTask) { \u00a0 if (networkMonitor.isOnline) { \u00a0 \u00a0 try { await httpPost(task); markDone(task); } \u00a0 \u00a0 catch (e) { await enqueue(task); } \u00a0 \/\/ \u4e34\u65f6\u5931\u8d25\u4e5f\u5165\u961f \u00a0 } else { \u00a0 \u00a0 await enqueue(task); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ \u79bb\u7ebf&#xff1a;\u4ec5\u843d\u5e93 \u00a0 \u00a0 toast(&#039;\u5df2\u79bb\u7ebf\u4fdd\u5b58&#xff0c;\u8054\u7f51\u540e\u81ea\u52a8\u540c\u6b65&#039;); \u00a0 } } &#096;&#096;&#096;<\/p>\n<p>### 4.4 L2&#xff1a;\u7eed\u4f20\u7f16\u6392&#xff08;Flush Controller&#xff09;<\/p>\n<p>\u7f51\u7edc\u6062\u590d\u65f6&#xff0c;\u7531\u7f16\u6392\u5668\u6309**\u987a\u5e8f &#043; \u5e76\u53d1\u5ea6 &#043; \u9000\u907f**\u8fdb\u884c\u7eed\u4f20&#xff0c;\u907f\u514d\u8bf7\u6c42\u98ce\u66b4&#xff1a;<\/p>\n<p>&#096;&#096;&#096;ts async function flush() { \u00a0 const tasks &#061; (await allPending()) \u00a0 \u00a0 .filter(t &#061;&gt; t.status &#061;&#061;&#061; &#039;pending&#039;) \u00a0 \u00a0 .sort((a, b) &#061;&gt; a.meta.createdAt &#8211; b.meta.createdAt); \/\/ FIFO<\/p>\n<p>\u00a0 const CONCURRENCY &#061; 3; \u00a0 for (let i &#061; 0; i &lt; tasks.length; i &#043;&#061; CONCURRENCY) { \u00a0 \u00a0 const batch &#061; tasks.slice(i, i &#043; CONCURRENCY); \u00a0 \u00a0 await Promise.all(batch.map(sendOne)); \u00a0 \u00a0 if (!networkMonitor.isOnline) break; \/\/ \u4e2d\u9014\u53c8\u65ad\u7f51&#xff0c;\u7acb\u523b\u6682\u505c \u00a0 } }<\/p>\n<p>async function sendOne(task: UpdateTask) { \u00a0 task.status &#061; &#039;inflight&#039;; \u00a0 try { \u00a0 \u00a0 const res &#061; await httpPost(task); \u00a0 \u00a0 if (res.status &#061;&#061;&#061; 409) return resolveConflict(task, res); \/\/ \u51b2\u7a81 \u00a0 \u00a0 await markDone(task); \u00a0 } catch (e) { \u00a0 \u00a0 task.meta.retry&#043;&#043;; \u00a0 \u00a0 if (task.meta.retry &gt; 5) task.status &#061; &#039;dead&#039;; \/\/ \u5165\u6b7b\u4fe1\u961f\u5217 \u00a0 \u00a0 else await backoff(task); \/\/ \u6307\u6570\u9000\u907f\u540e\u91cd\u6392 \u00a0 \u00a0 await set(QUEUE_PREFIX &#043; task.id, task); \u00a0 } } &#096;&#096;&#096;<\/p>\n<p>**\u6682\u505c\u8bed\u4e49**&#xff1a;&#096;flush&#096; \u4e2d\u4efb\u4f55\u4e00\u6b21\u63a2\u6d4b\u5230 &#096;isOnline &#061;&#061;&#061; false&#096;&#xff0c;\u7acb\u5373 &#096;break&#096;&#xff0c;\u5269\u4f59\u4efb\u52a1\u4fdd\u6301 &#096;pending&#096;&#xff0c;\u7b49\u5f85\u4e0b\u6b21 &#096;online&#096; \u4e8b\u4ef6\u518d\u89e6\u53d1 &#096;flush()&#096;\u3002\u8fd9\u5c31\u662f&#034;\u6682\u505c\u2014\u6062\u590d&#034;\u7684\u95ed\u73af\u3002<\/p>\n<p>### 4.5 \u51b2\u7a81\u89e3\u51b3\u7b56\u7565<\/p>\n<p>\u79bb\u7ebf\u671f\u95f4\u5176\u4ed6\u7aef\u53ef\u80fd\u5df2\u4fee\u6539\u540c\u4e00\u8d44\u6e90&#xff0c;\u7eed\u4f20\u65f6\u540e\u7aef\u8fd4\u56de &#096;409 Conflict&#096;\u3002\u5e38\u89c1\u7b56\u7565&#xff1a;<\/p>\n<p>| \u7b56\u7565 | \u9002\u7528\u573a\u666f | \u505a\u6cd5 | |&#8212;&#8212;|&#8212;&#8212;&#8212;-|&#8212;&#8212;| | \u6700\u540e\u5199\u5165\u83b7\u80dc&#xff08;LWW&#xff09; | \u4f4e\u534f\u4f5c\u3001\u53ef\u63a5\u53d7\u8986\u76d6 | \u4ee5 &#096;updatedAt&#096; \u53d6\u6700\u65b0&#xff0c;\u524d\u7aef\u5f39&#034;\u5df2\u88ab\u4ed6\u4eba\u4fee\u6539&#034;\u63d0\u793a | | \u7248\u672c\u53f7\u6821\u9a8c&#xff08;OCC&#xff09; | \u901a\u7528 | \u63d0\u4ea4\u5e26 &#096;baseVersion&#096;&#xff0c;\u4e0d\u5339\u914d\u5219\u62d2\u7edd&#xff0c;\u524d\u7aef\u62c9\u65b0\u57fa\u7ebf\u540e\u5408\u5e76 | | \u64cd\u4f5c\u53d8\u6362&#xff08;OT&#xff09; | \u534f\u540c\u7f16\u8f91 | \u5c06\u66f4\u65b0\u8868\u8fbe\u4e3a\u64cd\u4f5c&#xff0c;\u670d\u52a1\u7aef\u91cd\u6392 | | CRDT | \u9ad8\u5e76\u53d1\u65e0\u4e2d\u5fc3 | \u6570\u636e\u7ed3\u6784\u5929\u7136\u53ef\u5408\u5e76&#xff0c;\u65e0\u9700\u51b2\u7a81\u5904\u7406 |<\/p>\n<p>&gt; \u63a8\u8350\u9ed8\u8ba4\u91c7\u7528 **OCC&#xff08;\u4e50\u89c2\u5e76\u53d1\u63a7\u5236&#xff09;**&#xff1a;\u6210\u672c\u53ef\u63a7&#xff0c;\u4e14\u80fd\u628a&#034;\u6682\u505c\u2014\u6062\u590d\u2014\u51b2\u7a81&#034;\u4e09\u6bb5\u903b\u8f91\u89e3\u8026\u3002<\/p>\n<p>&#8212;<\/p>\n<p>## 5. \u72b6\u6001\u673a\u4e0e\u8fb9\u754c\u60c5\u51b5<\/p>\n<p>\u66f4\u65b0\u4efb\u52a1\u5efa\u8bae\u7528\u663e\u5f0f\u72b6\u6001\u673a&#xff0c;\u907f\u514d&#034;\u534a\u63d0\u4ea4&#034;\u5e7d\u7075\u4efb\u52a1&#xff1a;<\/p>\n<p>&#096;&#096;&#096; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 enqueue \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u5728\u7ebf\u63d0\u4ea4\u5931\u8d25 \u00a0 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u00a0\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25b6 \u00a0\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u00a0 \u2502 \u00a0pending \u00a0\u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 pending \u00a0\u2502 \u00a0 \u2514\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2518 \u00a0\u25c0\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u00a0 \u2514\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2518 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u53d1\u9001 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2502 \u6536\u5230 409 \u00a0 \u00a0 \u00a0 \u00a0 \u25bc \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u25bc \u00a0 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u00a0\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u00a0 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u00a0 \u2502 inflight \u2502 \u00a0\u2502 \u00a0done \u00a0 \u2502 \u00a0 \u2502 conflict \u2502 \u2500\u2500\u25b6 resolveConflict \u00a0 \u2514\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2518 \u00a0\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u00a0 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u00a0 \u00a0 \u00a0 \u00a0\u2502 \u91cd\u8bd5\u8017\u5c3d \u00a0 \u00a0 \u00a0 \u00a0\u25bc \u00a0 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u00a0 \u2502 \u00a0 dead \u00a0 \u2502 \u00a0\u2500\u2500\u25b6 \u6b7b\u4fe1\u961f\u5217&#xff08;\u4eba\u5de5\/\u65e5\u5fd7&#xff09; \u00a0 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 &#096;&#096;&#096;<\/p>\n<p>**\u5fc5\u5904\u7406\u7684\u8fb9\u754c\u60c5\u51b5&#xff1a;** &#8211; **\u91cd\u8fde\u77ac\u95f4\u91cd\u590d\u63d0\u4ea4**&#xff1a;\u7528\u4efb\u52a1 &#096;id&#096; \u5e42\u7b49\u952e&#xff0c;\u540e\u7aef\u505a\u53bb\u91cd&#xff08;\u540c\u4e00 &#096;id&#096; \u4ec5\u751f\u6548\u4e00\u6b21&#xff09;\u3002 &#8211; **\u9875\u9762\u5173\u95ed\u5bfc\u81f4 inflight \u4e22\u5931**&#xff1a;&#096;inflight&#096; \u5728\u91cd\u8f7d\u540e\u56de\u9000\u4e3a &#096;pending&#096; \u91cd\u65b0\u53d1\u9001&#xff08;\u540e\u7aef\u5e42\u7b49\u515c\u5e95&#xff09;\u3002 &#8211; **\u961f\u5217\u65e0\u9650\u81a8\u80c0**&#xff1a;\u8bbe\u6700\u5927\u5bb9\u91cf\u4e0e TTL&#xff0c;\u8fc7\u671f\u4efb\u52a1\u8f6c &#096;dead&#096; \u5e76\u544a\u8b66\u3002 &#8211; **\u6ce8\u9500\/\u5207\u6362\u8d26\u53f7**&#xff1a;\u6e05\u7a7a\u961f\u5217\u6216\u6309 &#096;userId&#096; \u9694\u79bb&#xff0c;\u9632\u6b62\u4e32\u53f7\u4e32\u6570\u636e\u3002<\/p>\n<p>&#8212;<\/p>\n<p>## 6. \u53ef\u89c2\u6d4b\u6027<\/p>\n<p>\u79bb\u7ebf\u66f4\u65b0\u7b56\u7565&#034;\u770b\u4e0d\u89c1&#034;\u5c31\u5bb9\u6613\u51fa\u95ee\u9898&#xff0c;\u5efa\u8bae\u57cb\u70b9&#xff1a;<\/p>\n<p>&#8211; &#096;queue_depth&#096;&#xff1a;\u5f53\u524d pending \u4efb\u52a1\u6570&#xff08;\u53cd\u6620\u79bb\u7ebf\u5806\u79ef\u538b\u529b&#xff09; &#8211; &#096;sync_latency&#096;&#xff1a;\u4ece enqueue \u5230 done \u7684\u65f6\u5ef6 &#8211; &#096;conflict_rate&#096;&#xff1a;\u51b2\u7a81\u5360\u6bd4&#xff0c;\u8fc7\u9ad8\u8bf4\u660e OCC \u7c92\u5ea6\u8fc7\u7c97 &#8211; &#096;dead_letter_count&#096;&#xff1a;\u6b7b\u4fe1\u6570\u91cf&#xff0c;\u9700\u544a\u8b66 &#8211; &#096;offline_duration&#096;&#xff1a;\u5355\u6b21\u79bb\u7ebf\u65f6\u957f\u5206\u5e03<\/p>\n<p>&#8212;<\/p>\n<p>## 7. \u6700\u4f73\u5b9e\u8df5\u6e05\u5355<\/p>\n<p>1. **\u5199\u64cd\u4f5c\u4e00\u5f8b\u8d70\u8c03\u5ea6\u5668**&#xff0c;\u4e0d\u8981\u5728\u4e1a\u52a1\u4ee3\u7801\u91cc\u6563\u843d &#096;fetch&#096;&#xff0c;\u7531 &#096;UpdateScheduler&#096; \u7edf\u4e00\u51b3\u5b9a\u76f4\u53d1\u8fd8\u662f\u5165\u961f\u3002 2. **\u672c\u5730\u4f18\u5148\u53cd\u9988**&#xff1a;\u79bb\u7ebf\u4fdd\u5b58\u5373\u89c6\u4e3a&#034;\u5df2\u4fdd\u5b58&#xff08;\u5f85\u540c\u6b65&#xff09;&#034;&#xff0c;\u7ed9\u786e\u5b9a\u611f&#xff0c;\u4e0d\u629b\u7f51\u7edc\u9519\u8bef\u3002 3. **\u7248\u672c\u66f4\u65b0\u79bb\u7ebf\u6682\u505c**&#xff1a;SW \u4e0d\u8981\u5728\u79bb\u7ebf\u65f6\u81ea\u52a8\u6fc0\u6d3b&#xff0c;\u8054\u7f51\u540e\u7531\u7528\u6237\u89e6\u53d1\u5237\u65b0\u3002 4. **\u7eed\u4f20\u8981\u6709\u7f16\u6392**&#xff1a;\u5e76\u53d1\u5ea6\u3001\u9000\u907f\u3001\u5e42\u7b49\u3001\u65ad\u70b9\u6682\u505c&#xff0c;\u7f3a\u4e00\u4e0d\u53ef\u3002 5. **\u51b2\u7a81\u8981\u663e\u5f0f\u5904\u7406**&#xff1a;\u9ed8\u8ba4 OCC&#xff0c;\u5fc5\u8981\u65f6\u5347\u7ea7\u5230 CRDT&#xff1b;\u7edd\u4e0d\u9759\u9ed8\u8986\u76d6\u7528\u6237\u6570\u636e\u3002 6. **\u961f\u5217\u8981\u53ef\u89c2\u6d4b\u3001\u53ef\u6e05\u7406**&#xff1a;\u66b4\u9732\u6df1\u5ea6\u4e0e\u6b7b\u4fe1&#xff0c;\u8bbe\u7f6e\u5bb9\u91cf\u4e0a\u9650\u4e0e TTL\u3002 7. **\u5b58\u50a8\u9009\u578b**&#xff1a;\u961f\u5217\u6301\u4e45\u5316\u4f18\u5148 **IndexedDB**&#xff08;\u5bb9\u91cf\u5927\u3001\u5f02\u6b65\u3001\u4e8b\u52a1\u5b89\u5168&#xff09;&#xff0c;\u6781\u5c0f\u6570\u636e\u53ef\u7528 &#096;localStorage&#096; \u515c\u5e95\u3002<\/p>\n<p>&#8212;<\/p>\n<p>## 8. \u6280\u672f\u9009\u578b\u53c2\u8003<\/p>\n<p>| \u80fd\u529b | \u63a8\u8350 | \u5907\u6ce8 | |&#8212;&#8212;|&#8212;&#8212;|&#8212;&#8212;| | \u672c\u5730\u6301\u4e45\u5316\u961f\u5217 | IndexedDB&#xff08;idb \/ Dexie&#xff09; | \u5f02\u6b65\u3001\u5bb9\u91cf\u5927\u3001\u652f\u6301\u4e8b\u52a1 | | \u7f51\u7edc\u63a2\u6d4b | \u81ea\u5b9a\u4e49 &#043; \u5fc3\u8df3 | &#096;navigator.onLine&#096; \u4ec5\u4f5c\u521d\u5224 | | PWA \u66f4\u65b0 | Workbox &#043; \u81ea\u5b9a\u4e49 SW \u6d88\u606f | \u63a7\u5236\u6fc0\u6d3b\u65f6\u673a | | \u51b2\u7a81\u5408\u5e76 | \u81ea\u7814 OCC \/ Yjs(CRDT) | \u534f\u540c\u573a\u666f\u7528 Yjs | | \u91cd\u8bd5\u9000\u907f | \u81ea\u7814\u6216 p-retry | \u6307\u6570\u9000\u907f &#043; \u6296\u52a8 |<\/p>\n<p>&#8212;<\/p>\n<p>_\u6587\u6863\u7ed3\u675f\u3002\u5982\u9700\u9488\u5bf9\u5177\u4f53\u6846\u67b6&#xff08;React \/ Vue \/ Electron \/ Flutter Web&#xff09;\u6216\u540e\u7aef\u534f\u8bae&#xff08;REST \/ GraphQL \/ WebSocket&#xff09;\u8865\u5145\u843d\u5730\u793a\u4f8b&#xff0c;\u53ef\u5728\u6b64\u57fa\u7840\u4e0a\u6269\u5c55\u5bf9\u5e94\u7ae0\u8282\u3002_ \u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&gt; \u7248\u672c&#xff1a;v1.0 &#xff5c; \u9002\u7528\u8303\u56f4&#xff1a;PWA \/ SPA \/ \u684c\u9762\u7aef&#xff08;Electron\u3001Tauri \u7b49&#xff09;\u53ca\u79fb\u52a8\u7aef Hybrid \u524d\u7aef\u5e94\u7528 &gt; \u5173\u952e\u8bcd&#xff1a;\u79bb\u7ebf\u4f18\u5148&#xff08;Offline-First&#xff09;\u3001\u66f4\u65b0\u6682\u505c\u3001\u65ad\u70b9\u7eed\u4f20\u3001\u51b2\u7a81\u89e3\u51b3\u3001Service Worker\u3001\u672c\u5730\u961f\u5217<br \/>\n&#8212;<br \/>\n## 1. \u80cc\u666f\u4e0e\u95ee\u9898\u5b9a\u4e49<br \/>\n\u73b0\u4ee3\u524d\u7aef\u5e94\u7528\u8d8a\u6765\u8d8a\u591a\u5730\u8fd0\u884c\u5728\u5f31\u7f51\u6216\u65ad\u7f51\u73af\u5883&#xff08;\u5730\u94c1\u3001\u7535\u68af\u3001<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[87],"topic":[],"class_list":["post-90010","post","type-post","status-publish","format-standard","hentry","category-server","tag-87"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u524d\u7aef\u5e94\u7528\u79bb\u7ebf\u6682\u505c\u66f4\u65b0\u7b56\u7565\u6280\u672f\u6587\u6863 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/90010.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u524d\u7aef\u5e94\u7528\u79bb\u7ebf\u6682\u505c\u66f4\u65b0\u7b56\u7565\u6280\u672f\u6587\u6863 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"&gt; \u7248\u672c&#xff1a;v1.0 &#xff5c; \u9002\u7528\u8303\u56f4&#xff1a;PWA \/ SPA \/ \u684c\u9762\u7aef&#xff08;Electron\u3001Tauri \u7b49&#xff09;\u53ca\u79fb\u52a8\u7aef Hybrid \u524d\u7aef\u5e94\u7528 &gt; \u5173\u952e\u8bcd&#xff1a;\u79bb\u7ebf\u4f18\u5148&#xff08;Offline-First&#xff09;\u3001\u66f4\u65b0\u6682\u505c\u3001\u65ad\u70b9\u7eed\u4f20\u3001\u51b2\u7a81\u89e3\u51b3\u3001Service Worker\u3001\u672c\u5730\u961f\u5217 --- ## 1. \u80cc\u666f\u4e0e\u95ee\u9898\u5b9a\u4e49 \u73b0\u4ee3\u524d\u7aef\u5e94\u7528\u8d8a\u6765\u8d8a\u591a\u5730\u8fd0\u884c\u5728\u5f31\u7f51\u6216\u65ad\u7f51\u73af\u5883&#xff08;\u5730\u94c1\u3001\u7535\u68af\u3001\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/90010.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-04T06:08:34+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/90010.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/90010.html\",\"name\":\"\u524d\u7aef\u5e94\u7528\u79bb\u7ebf\u6682\u505c\u66f4\u65b0\u7b56\u7565\u6280\u672f\u6587\u6863 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-04T06:08:34+00:00\",\"dateModified\":\"2026-08-04T06:08:34+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/90010.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/90010.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/90010.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u524d\u7aef\u5e94\u7528\u79bb\u7ebf\u6682\u505c\u66f4\u65b0\u7b56\u7565\u6280\u672f\u6587\u6863\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u524d\u7aef\u5e94\u7528\u79bb\u7ebf\u6682\u505c\u66f4\u65b0\u7b56\u7565\u6280\u672f\u6587\u6863 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/90010.html","og_locale":"zh_CN","og_type":"article","og_title":"\u524d\u7aef\u5e94\u7528\u79bb\u7ebf\u6682\u505c\u66f4\u65b0\u7b56\u7565\u6280\u672f\u6587\u6863 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"&gt; \u7248\u672c&#xff1a;v1.0 &#xff5c; \u9002\u7528\u8303\u56f4&#xff1a;PWA \/ SPA \/ \u684c\u9762\u7aef&#xff08;Electron\u3001Tauri \u7b49&#xff09;\u53ca\u79fb\u52a8\u7aef Hybrid \u524d\u7aef\u5e94\u7528 &gt; \u5173\u952e\u8bcd&#xff1a;\u79bb\u7ebf\u4f18\u5148&#xff08;Offline-First&#xff09;\u3001\u66f4\u65b0\u6682\u505c\u3001\u65ad\u70b9\u7eed\u4f20\u3001\u51b2\u7a81\u89e3\u51b3\u3001Service Worker\u3001\u672c\u5730\u961f\u5217 --- ## 1. \u80cc\u666f\u4e0e\u95ee\u9898\u5b9a\u4e49 \u73b0\u4ee3\u524d\u7aef\u5e94\u7528\u8d8a\u6765\u8d8a\u591a\u5730\u8fd0\u884c\u5728\u5f31\u7f51\u6216\u65ad\u7f51\u73af\u5883&#xff08;\u5730\u94c1\u3001\u7535\u68af\u3001","og_url":"https:\/\/www.wsisp.com\/helps\/90010.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-04T06:08:34+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/90010.html","url":"https:\/\/www.wsisp.com\/helps\/90010.html","name":"\u524d\u7aef\u5e94\u7528\u79bb\u7ebf\u6682\u505c\u66f4\u65b0\u7b56\u7565\u6280\u672f\u6587\u6863 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-04T06:08:34+00:00","dateModified":"2026-08-04T06:08:34+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/90010.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/90010.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/90010.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u524d\u7aef\u5e94\u7528\u79bb\u7ebf\u6682\u505c\u66f4\u65b0\u7b56\u7565\u6280\u672f\u6587\u6863"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/90010","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=90010"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/90010\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=90010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=90010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=90010"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=90010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}