HTTP/2推送JSON有效负载 [英] HTTP/2 Push JSON Payload

查看:138
本文介绍了HTTP/2推送JSON有效负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http/2服务器推送的最常用情况是抢先将资产文件(例如javascript和css文件)推送到浏览器.我想知道可以使用http/2服务器推送将动态有效负载(例如JSON文档)发送到客户端应用程序吗?在 http2-spec 中,它没有提及任何内容.谁能详细说明一下?为什么或为什么不呢?

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?

推荐答案

HTTP/2不能替代websocket,因为您发出请求(例如,网页)并且可能会收回一些资源(例如,网络页,显示网页所需的CSS,运行该网页所需的JavaScript ...等.

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因此并不是真正的双向,因为它仍然响应初始请求.

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

因此,如果您打算发送JSON请求以响应初始请求,那就很好了-它只是另一个资源,与CSS和javascript差不多.

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.

但是,如果您打算保持频道开放以继续发送进一步的JSON负载以使页面保持最新状态,那么这不是HTTP/2的目的.这就是websocket的用途.

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.

此问题提供了有关HTTP/2和Websockets的更多详细信息:执行HTTP/2使websocket过时?

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

这篇关于HTTP/2推送JSON有效负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆