为什么用放气,而不是gzip的由Apache的服务文本文件? [英] Why use deflate instead of gzip for text files served by Apache?

查看:132
本文介绍了为什么用放气,而不是gzip的由Apache的服务文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么优势做HTML,CSS和JavaScript由LAMP服务器提供文件,这两种方法的报价。有没有更好的方法?

该服务器提供了使用JSON到地图应用程序的信息,小文件这样高的音量。

参见<一个href=\"http://stackoverflow.com/questions/211284/is-there-any-performance-hit-involved-in-choosing-gzip-over-deflate-for-http-co\">Is有参与选择任何性能损失的gzip紧缩以上为HTTP COM pression?


解决方案

  

为什么用放气,而不是gzip的由Apache的服务文本文件?


答案很简单的不要


2616 定义为紧缩:


  

紧缩在RFC 1950年定义的结合的zlib格式放气,在RFC描述COM pression机制1951年


zlib数据格式在 RFC定义1950年为

  0 1
     + --- + --- +
     | CMF | FLG | (更多 - &GT;)
     + --- + --- +       0 1 2 3
     + --- + --- + --- + --- +
     | DICTID | (更多 - &GT;)
     + --- + --- + --- + --- +     + ===================== + --- + --- + --- + --- +
     | ... COM pressed数据... | ADLER32 |
     + ===================== + --- + --- + --- + --- +

所以,几头和ADLER32校验

2616 gzip的定义为:


  

gzip压缩的文件,COM pression程序产生的编码格式
         在RFC 1952年[25]中描述的gzip(GNU zip的)。这种格式是一种
         的Lempel-Ziv编码(LZ77)有32位CRC。


RFC 1952年定义了COM pressed数据:


  

格式presently使用COM pression的DEFLATE方法,但可以很容易地扩展到使用其他COM pression方法。


CRC-32是比ADLER32


  

相比相同长度的一个循环冗余校验,它交易可靠性速度(preferring后者)。


所以...我们有使用相同作为COM pression算法2个COM pression机制,但不同的算法头和校验

现在,底层的TCP数据包已经 pretty可靠的,所以这里的问题不是阿德勒32 VS href=\"http://www.gzip.org/zlib/rfc-gzip.html\"> CRC-32 的GZIP使用


原来,在实施了不正确的deflate算法几年许多浏览器。相反,在1950年的RFC期待zlib的头,他们只是期望COM pressed有效载荷。同样各种web服务器犯同样的错误。

因此​​,在浏览器开始实施的模糊逻辑的年紧缩的实施,他们尝试zlib的头和阿德勒校验,如果失败,他们尝试的有效载荷。

具有这样的复杂的逻辑的结果是,它经常破裂。神韵工作室有一个用户贡献的测试部分,展示了形势有多么糟糕。

例如:紧缩在Safari 4.0的作品,但在Safari 5.1被打破,它也总是对IE浏览器的问题。


那么,做最好的事情是完全避免紧缩,未成年人的速度增加(由于阿德勒32)不值得断载荷的风险。

What advantages do either method offer for html, css and javascript files served by a LAMP server. Are there better alternatives?

The server provides information to a map application using Json, so a high volume of small files.

See also Is there any performance hit involved in choosing gzip over deflate for http compression?

解决方案

Why use deflate instead of gzip for text files served by Apache?

The simple answer is don't.


RFC 2616 defines deflate as:

deflate The "zlib" format defined in RFC 1950 in combination with the "deflate" compression mechanism described in RFC 1951

The zlib format is defined in RFC 1950 as :

     0   1
     +---+---+
     |CMF|FLG|   (more-->)
     +---+---+

       0   1   2   3
     +---+---+---+---+
     |     DICTID    |   (more-->)
     +---+---+---+---+

     +=====================+---+---+---+---+
     |...compressed data...|    ADLER32    |
     +=====================+---+---+---+---+

So, a few headers and an ADLER32 checksum

RFC 2616 defines gzip as:

gzip An encoding format produced by the file compression program "gzip" (GNU zip) as described in RFC 1952 [25]. This format is a Lempel-Ziv coding (LZ77) with a 32 bit CRC.

RFC 1952 defines the compressed data as:

The format presently uses the DEFLATE method of compression but can be easily extended to use other compression methods.

CRC-32 is slower than ADLER32

Compared to a cyclic redundancy check of the same length, it trades reliability for speed (preferring the latter).

So ... we have 2 compression mechanisms that use the same algorithm for compression, but a different algorithm for headers and checksum.

Now, the underlying TCP packets are already pretty reliable, so the issue here is not Adler 32 vs CRC-32 that GZIP uses.


Turns out many browsers over the years implemented an incorrect deflate algorithm. Instead of expecting the zlib header in RFC 1950 they simply expected the compressed payload. Similarly various web servers made the same mistake.

So, over the years browsers started implementing a fuzzy logic deflate implementation, they try for zlib header and adler checksum, if that fails they try for payload.

The result of having complex logic like that is that it is often broken. Verve Studio have a user contributed test section that show how bad the situation is.

For example: deflate works in Safari 4.0 but is broken in Safari 5.1, it also always has issues on IE.


So, best thing to do is avoid deflate altogether, the minor speed boost (due to adler 32) is not worth the risk of broken payloads.

这篇关于为什么用放气,而不是gzip的由Apache的服务文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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