How web push protocol works?

那年仲夏 提交于 2020-11-29 03:56:09

问题


Problem

I am wondering how webpush protocol works? Does it keep some kind of connection open like WebSocket protocol? Or does it use mechanism similar to polling?

Tried

According to documentation WebPush uses HTTP 2.0 server push:

A simple protocol for the delivery of real-time events to user agents is described. This scheme uses HTTP/2 server push.

Server push wikipedia:

HTTP/2 Server Push is not a notification mechanism from server to client. Instead, pushed resources are used by the client when it may have otherwise produced a request to get the resource anyway;

HTTP/2 server push example scenario:

Consider a website with three resources: index.html, styles.css and script.js. When a user, through their browser, connects to the home page of this website they automatically retrieve index.html. As the browser parses the HTML text in index.html, it finds instructions that will require styles.css and script.js. At that point, the browser will issue requests to get these other two files.

With HTTP/2 Push, the server can take the initiative by having rules that trigger content to be sent even before it is requested. In this example scenario, the server knows that anyone requesting index.html will need styles.css and script.js, so it can push them to the client immediately without waiting for the client to request them.

According to HTTP/2 server push itt seems that WebPush protocol should return some kind of notifications before they are requested by client. But I am no sure about it. So here is my question: How it exactly works underhood?

来源:https://stackoverflow.com/questions/62673508/how-web-push-protocol-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!