pre平头标记使用gzip支持 [英] Pre flush head tag with gzip support

查看:152
本文介绍了pre平头标记使用gzip支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://developer.yahoo.com/performance/rules.html

有它被赋予它是很好的preflush头标记。

There it is given it is good to preflush the head tag .

不过,我有一个问题,而使用gzip有帮助吗? (我用的Apache2)。
我认为,整个文件将在一杆得到gziped,然后发送给客户端。

But I have a question will it help while using gzip ? (I am using apache2). I think full document will get gziped at one shot and then send to the client.

或者是它也可能有gzip的以及pre-平头标记

or is it also possible to have gzip as well as pre-flush the head tag

推荐答案

EDITED

这个问题的原始版本建议我们正在处理的HTTP头,而不是< HEAD> 在HTML文档部分。我将离开我原来的答复如下,但它实际上已经没有意义这个具体的问题。

The original version of this question suggested we were dealing with HTTP headers rather than the <head> section on an HTML document. I will leave my original answer below, but it actually has no relevance to this specific question.

要回答这个问题pre-刷新&LT; HEAD&GT; 文档的部分 - 而这将有可能用gzip做这个组合,它可能不是没有过比Apache得到gzip的过程更加精细的控制成为可能。这是可能打破gzip压缩的流成块,可以DECOM pressed自己(的看到这个),但如果控制Apache的gzip的实施,这种程度的一种方式,然后我没有意识到这一点。

To answer the question about pre-flushing the <head> section of a document - while it would be possible to do this in combination with gzip, it is probably not possible without more granular control over the gzip process than Apache affords. It is possible to break a gzipped stream into chunks that can be decompressed on their own (see this) but if there is a way to control Apache's gzip implementation to such a degree then I am not aware of it.

这样做可能会降低的gzip的功效,使得COM pressed规模大,而且只会是值得做的,当&LT;的; HEAD&GT文件特别大,比如说超过10KB(这是通过阅读有关引擎盖下如何gzip的作品我来到一个有点任意值,绝对应该的的被视为福音)。

Doing so would likely decrease the efficacy of the gzip, making the compressed size larger, and would only be worth doing when the <head> of a document was particularly large, say, greater than 10KB (this is a somewhat arbitrary value I arrived at by reading about how gzip works under the bonnet, and should definitely not be taken as gospel).

原来的答复,与HTTP头:

Original answer, relating to the HTTP headers:

单纯从HTTP协议的角度出发,而不是正是你将如何实现这一个基于Apache服务器上,我看不到任何理由,你为什么不能preflush头,并使用gzip COM preSS身体。牢记一个事实,即标题是从不的gzip压缩(如果他们是,如何将客户知道他们过得好吗?)内容的传输编码应该当您发送头无影响

Purely from the viewpoint of the HTTP protocol, rather than exactly how you would implement it on an Apache based server, I can't see any reason why you can't preflush the headers and also use gzip to compress the body. Keeping in mind that fact that the headers are never gzipped (if they were, how would the client know they had been?), the transfer encoding of the content should have no effect on when you send the headers.

有,但两件事情要记住:

There are, however a couple of things to keep in mind:


  • 一旦头已发送,你不能改变主意了传输编码。所以,如果你发送的状态,该机构将用gzip压缩的头,然后意识到,你的身体是只有4个字节,你仍然会有无论如何gzip压缩它,这实际上增加身体的大小。这可能不会是一个问题,除非你被省略的Content-Length:头,而这可能是不好的做法,因为这意味着你不能使用持久连接。这会导致下一个点...

  • 您不能发送的Content-Length:头在这个secenario。这是因为你不知道身体的大小是什么,直到你有COM pressed它,届时它已准备好发送,所以你是不是真的(从视图中的服务器的点)preflushing头,即使你不单独给他们,你开始发送体前。

  • 如果你花了很长的时间的时间COM preSS的邮件正​​文(慢/负载过重的服务器,非常庞大的身躯等等等等),并且不启动COM pression后才已发送的报头,是有风险的客户可能会超时等待响应的其余部分。这完全取决于客户端,但这么多的HTTP客户端实现了那里,这种可能性不能完全忽视。

  • Once the headers have been sent, you can't change your mind about the transfer encoding. So if you send the headers which state that the body will be gzipped, then realise that your body is only 4 bytes, your would still have to gzip it anyway, which would actually increase the size of the body. This probably wouldn't be a problem unless you were omitting the Content-Length: header which while possible, is bad practice as it means you cannot use persistent connections. This leads on to the next point...
  • You cannot send a Content-Length: header in this secenario. This is because you don't know what the size of the body is until you have compressed it, by which time it is ready to send, so you are not really (from the server's point of view) preflushing the headers, even if you do send them seperately before you start to send the body.
  • If it takes you a long time time to compress the body of the message (slow/heavily loaded server, very large body etc etc), and you don't start the compression until after you have sent the headers, there is a risk the client may time out waiting for the rest of the response. This depends entirely on the client, but the are so many HTTP client implementations out there that this possibility cannot be totally discounted.

在短,是有可能做到这一点,但没有包罗万象的,是的,做或不,不这样做的答案 - 不管你会做这取决于每个请求和它的性质的响应。

In short, yes it is possible to do it, but there is no catch-all, "Yes, do it" or "No, don't do it" answer - whether you would do it depends on each request and the nature of it's response.

这篇关于pre平头标记使用gzip支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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