从 Web 角度看,通知 API 和推送 API 之间的区别

Difference between Notifications API and Push API from Web perspective

开发Web通知时Chrome Notifications API and the Push Notification API有什么区别。什么时候应该使用它们,它们有何不同?

通知API Notifications API 允许网页或应用程序发送在系统级别显示在页面外的通知;这让网络应用程序可以向用户发送信息,即使应用程序处于空闲状态或在后台也是如此。本文介绍了在您自己的应用程序中使用此 API 的基础知识。

https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API

推API Push API 使 web 应用程序能够接收从服务器推送给它们的消息,无论 web 应用程序是否在前台,甚至当前是否在用户代理上加载。这使开发人员可以向选择加入的用户提供异步通知和更新,从而更好地参与及时的新内容。 https://developer.mozilla.org/en/docs/Web/API/Push_API

查看这些链接以获取更多信息: https://www.w3.org/TR/push-api/ https://www.w3.org/TR/notifications/

这可能会令人困惑,但如果我做对了,自己寻找一个明确的答案,它是这样的:

通知API = 用于在用户开启您的site/app时发送通知,即使空闲或在后台。

Push API = 用于在用户未开启您的site/app时发送通知时刻.

浏览器兼容性

注意:对于 macOS 上的 Safari,Apple 有自己的推送通知 API: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/NotificationProgrammingGuideForWebsites/Introduction/Introduction.html

iOS 上的 Safari 仍然不支持这两个 API 中的任何一个(2021 年 2 月)。