在提供JavaScript文件时,默认情况下gzip是否安全

时间:2022-12-16 20:00:09

The question fits in the title. I am not interested in what the spec recommend but what the mix of browsers currently deployed support the best.

这个问题符合标题。我对规范推荐的内容不感兴趣,但目前部署的浏览器组合支持最佳。

  • Google Docs gzips their JS.
  • Google Docs gzips他们的JS。

  • The Google AJAX Libraries API CDN gzips JS.
  • Google AJAX Libraries API CDN gzips JS。

  • Yahoo gzips the JS for their YUI files.
  • 雅虎为他们的YUI文件gzips JS。

  • The Yahoo home page gzips their JS.
  • 雅虎主页gzips他们的JS。

So I think that the answer to my question is yes, it is fine to gzip JS for all browsers. But you'll let me know if you disagree.

所以我认为我的问题的答案是肯定的,为所有浏览器gzip JS都没关系。但如果你不同意,你会告诉我的。

2 个解决方案

#1


No, it's not. Firstly, the browser must declare that they accept gzip encoding as per Supercharging Javascript. On top of that, certain versions of IE6 have broken implementations, which is still an issue if they haven't been patched. More in The Internet Explorer Problem (with gzip encoding).

不,这不对。首先,浏览器必须声明它们按照Supercharging Javascript接受gzip编码。最重要的是,IE6的某些版本已经破坏了实现,如果它们没有被修补,这仍然是一个问题。更多Internet Explorer问题(使用gzip编码)。

#2


If you gzip your .js (or any other content), two problems may arise: 1. gzip increases the latency for uncompressible files (needs time to compress and uncompress) 2. an older browser may not understand the gzipped content. To avoid problem 2, you should examine the Accept-Encoding and User-Agent or other parts of the HTTP request to guess if the browser supports gzip. Modern browsers should not have problems with gzippd content.

如果你gzip你的.js(或任何其他内容),可能会出现两个问题:1。gzip增加了不可压缩文件的延迟(需要时间压缩和解压缩)2。较旧的浏览器可能无法理解gzip压缩的内容。为避免问题2,您应检查Accept-Encoding和User-Agent或HTTP请求的其他部分,以猜测浏览器是否支持gzip。现代浏览器应该没有gzippd内容的问题。

An excerpt from http://httpd.apache.org/docs/2.2/mod/mod_deflate.html: At first we probe for a User-Agent string that indicates a Netscape Navigator version of 4.x. These versions cannot handle compression of types other than text/html. The versions 4.06, 4.07 and 4.08 also have problems with decompressing html files. Thus, we completely turn off the deflate filter for them.

来自http://httpd.apache.org/docs/2.2/mod/mod_deflate.html的摘录:首先,我们探测用户代理字符串,该字符串表示Netscape Navigator版本的4.x.这些版本无法处理text / html以外的类型的压缩。版本4.06,4.07和4.08在解压缩html文件时也存在问题。因此,我们完全关闭它们的放气过滤器。

#1


No, it's not. Firstly, the browser must declare that they accept gzip encoding as per Supercharging Javascript. On top of that, certain versions of IE6 have broken implementations, which is still an issue if they haven't been patched. More in The Internet Explorer Problem (with gzip encoding).

不,这不对。首先,浏览器必须声明它们按照Supercharging Javascript接受gzip编码。最重要的是,IE6的某些版本已经破坏了实现,如果它们没有被修补,这仍然是一个问题。更多Internet Explorer问题(使用gzip编码)。

#2


If you gzip your .js (or any other content), two problems may arise: 1. gzip increases the latency for uncompressible files (needs time to compress and uncompress) 2. an older browser may not understand the gzipped content. To avoid problem 2, you should examine the Accept-Encoding and User-Agent or other parts of the HTTP request to guess if the browser supports gzip. Modern browsers should not have problems with gzippd content.

如果你gzip你的.js(或任何其他内容),可能会出现两个问题:1。gzip增加了不可压缩文件的延迟(需要时间压缩和解压缩)2。较旧的浏览器可能无法理解gzip压缩的内容。为避免问题2,您应检查Accept-Encoding和User-Agent或HTTP请求的其他部分,以猜测浏览器是否支持gzip。现代浏览器应该没有gzippd内容的问题。

An excerpt from http://httpd.apache.org/docs/2.2/mod/mod_deflate.html: At first we probe for a User-Agent string that indicates a Netscape Navigator version of 4.x. These versions cannot handle compression of types other than text/html. The versions 4.06, 4.07 and 4.08 also have problems with decompressing html files. Thus, we completely turn off the deflate filter for them.

来自http://httpd.apache.org/docs/2.2/mod/mod_deflate.html的摘录:首先,我们探测用户代理字符串,该字符串表示Netscape Navigator版本的4.x.这些版本无法处理text / html以外的类型的压缩。版本4.06,4.07和4.08在解压缩html文件时也存在问题。因此,我们完全关闭它们的放气过滤器。