为何考虑离线
先用本地数据渲染(Android Developers, n.d.;Kleppmann et al., 2019),网页用缓存(MDN, n.d.-a;web.dev, n.d.)。
连接状态提示
显示平和的横幅(MDN, n.d.-b;Miller, 1968),配合进度指示与空状态,并播报(WCAG 2.2 4.1.3)。
待发送与同步
排队稍后发送,冲突自动合并或让用户选择(Kleppmann et al., 2019),并支持撤销。
常见问题
- 所有功能都要离线?
- 从常用功能开始。
- 如何准确检测?
- 结合实际请求失败判断。
来源核查日期:2026-10-27
参考文献
- MDN Web Docs. (n.d.-a). Service Worker API. 用Service Worker缓存。
- MDN Web Docs. (n.d.-b). Navigator: onLine property. 在线状态检测。
- web.dev. (n.d.). The offline cookbook. 缓存策略。
- Android Developers. (n.d.). Build an offline-first app. 离线优先架构。
- Kleppmann, M., Wiggins, A., van Hardenberg, P., & McGranaghan, M. (2019). Local-first software: You own your data, in spite of the cloud. In Proceedings of the 2019 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software (pp. 154–178). ACM. 本地优先理念。
- Miller, R. B. (1968). Response time in man-computer conversational transactions. In Proceedings of the December 9–11, 1968, Fall Joint Computer Conference, Part I (pp. 267–277). ACM. 响应时间阈值。
- World Wide Web Consortium. (2023). Web Content Accessibility Guidelines (WCAG) 2.2. 4.1.3状态消息。
