请求之前的HTTP响应 [英] HTTP Response before Request

查看:138
本文介绍了请求之前的HTTP响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题可能听起来很愚蠢,但我只是想确定:

My question might sound stupid, but I just wanted to be sure:


  • 是否可以在获得之前发送HTTP响应请求该资源?

比如你有一个HTML页面 index.html 仅显示名为 img.jpg 的图片。
现在,如果您的服务器知道访问者每次都会请求HTML文件然后再请求jpg图像:

Say for example you have an HTML page index.html that only shows a picture called img.jpg. Now, if your server knows that a visitor will request the HTML file and then the jpg image every time:

服务器是否可以发送HTML文件之后的图像是为了节省时间吗?

Would it be possible for the server to send the image just after the HTML file to save time?

我知道HTTP是一种同步协议,所以理论上它不应该工作,但我只是想让某人确认(或不)。

I know that HTTP is a synchronous protocol, so in theory it should not work, but I just wanted someone to confirm it (or not).

推荐答案

如果有人请求/index.html并且您发送了两个回复(一个用于/index.html)另外对于/img.jpg),你怎么知道收件人会在第二个请求进入之前获得两个回复并知道如何处理它们?

If someone requests /index.html and you send two responses (one for /index.html and the other for /img.jpg), how do you know the recipient will get the two responses and know what to do with them before the second request goes in?

问题不在于发送。问题在于接收方可能会收到意外数据。

The problem is not really with the sending. The problem is with the receiver possibly getting unexpected data.

另一个问题是您拒绝客户端使用If-Modified-Since等HTTP缓存工具的能力和If-None-Match(即客户端可能不希望发送/img.jpg,因为它已经有一个缓存副本)。

One other issue is that you're denying the client the ability to use HTTP caching tools like If-Modified-Since and If-None-Match (i.e. the client might not want /img.jpg to be sent because it already has a cached copy).

那说,你可以近似使用 Comet 技术提升服务器效益。但这比简单地预测传入的HTTP请求要多得多。

That said, you can approximate the server-push benefits by using Comet techniques. But that is much more involved than simply anticipating incoming HTTP requests.

这篇关于请求之前的HTTP响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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