Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP/2 Push JSON Payload

The most use cases for http/2 server push is to pre-emptively push assets files (such as javascript and css files) to browser. I am wondering can http/2 server push be used to send dynamic payload such as JSON documents to client application? From the http2-spec, it doesn't mention anything about this. Can anyone elaborate more on this? Why or why not?

like image 600
Alex Avatar asked Jun 21 '16 21:06

Alex


People also ask

How do I send http2 request?

Command line use. To tell curl to use http2, either plain text or over TLS, you use the --http2 option (that is “dash dash http2”). curl defaults to HTTP/1.1 for HTTP: URLs so the extra option is necessary when you want http2 for that. For HTTPS URLs, curl will attempt to use http2.

How does http2 server push work?

HTTP/2 Server Push allows an HTTP/2-compliant server to send resources to an HTTP/2-compliant client before the client requests them. Server Push is a performance technique aimed at reducing latency by loading resources preemptively, even before the client knows they will be needed.

What is http 2 server push How does it ever from HTTP 1.1 Briefly explain it's workflow?

Server push – HTTP/2 servers push likely-to-be-used resources into a browser's cache, even before they're requested. This allows browsers to display content without additional request cycles. Increased security – Web browsers only support HTTP/2 via encrypted connections, increasing user and application security.

Is http 2 bidirectional?

HTTP/2 supports multiplexed, bidirectional streaming. This means that you can set up an unbroken TCP connection that allows data to flow continuously between client and server.


1 Answers

HTTP/2 is not intended as a replacement of websockets in that you make a request (e.g. a web page) and may get several resources back (e.g. The web page, the CSS needed to display the webpage, JavaScript needed to run that webpage... etc.).

HTTP/2 is therefore not truly bidirectional in that it still responds to an initial request.

So if you're intending to send the JSON request in response to the initial request then that's fine - it's just another resource in much the same as CSS and javascript.

However if you're intending to keep the channel open to continually send further JSON payloads to keep your page up to date then that's not what HTTP/2 is intended for. That's what websockets are for.

This question has some further details on HTTP/2 versus websockets: Does HTTP/2 make websockets obsolete?

like image 66
Barry Pollard Avatar answered Oct 19 '22 22:10

Barry Pollard