Server push is a method in HTTP/2 which allows server to send multiple responses for a single request. This feature decreases the latency in loading a webpage.
To make an HTTP/2 request client first checks if a TCP connection is already open or not. If not open then establishes a new TCP connection otherwise uses a the existing connection. It then sends an HTTP/2 request. If server feels that the client would need additional resources(also called as promises) or may request some additional resources afterwards the server along with the main response stream sends push promise streams hinting the client with the URL of the additional resources. Now client can request those additional resources via the same TCP connection. Client can also ignore the addition resources URLs or use the cached version if there is.
For every hinting resource a new response stream is created with only the resource headers not the actual content. This response stream is called as push stream. This streams are transferred via the same TCP connection. These streams have high priority then the original request i.e., sent to client before original request. The first frame of the push stream is called as push frame and is used to tell client that the server wants to push this additional resource.
This technique is useful while loading web pages which have external style sheets and script files attached to it. Developers don’t need to combine external resources anymore as HTTP/2 optimizes this issue.
Note: Server can only hint additional resource belonging to same origin policy.
Leave a Reply