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

查看:32
本文介绍了请求前的 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 和 If-None-Match 之类的 HTTP 缓存工具的能力(即客户端可能不希望发送/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天全站免登陆