Google Gmail、文档等如何获取更改推送通知?

发布于 2024-10-05 09:59:16 字数 66 浏览 0 评论 0原文

我假设客户端有一个 AJAX 请求轮询更新,但它的响应非常严格。有人可以更深入地了解他们可能在协议中所做的任何技巧吗?

I would assume that there is an AJAX request on the client side that polls for updates, but it is amazingly tight response. Can someone provide more insight into any tricks that they may be doing in the protocol?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城孤痞 2024-10-12 09:59:16

在这种情况下通常使用两种方法

  • 轮询:Javascript 代码每(例如)10 秒轮询一次服务器,看看是否有一些新消息要显示

  • 持久连接:XMLHttpRequest请求由客户端执行,服务器保持连接直到有消息(在本例中向客户端回复数据),或者如果达到给定的超时 - 那么客户端会再次尝试,依此类推。

谷歌可能使用第二个选项,它的回复和更新速度更快。

Two methods generally used in this case

  • Polling: the Javascript code polls the server every (for instance) 10 seconds to see if there is some fresh news to show

  • Persistent connection: the XMLHttpRequest request is performed by the client, and the server keeps the connection until there is some news (replies data to client in this case), or if a given time-out is reached - then the client tries again and so on.

Google probably uses the 2nd option, which is replying and updating faster.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文