如果我们不支持IE6,gzip Javascript文件是否有用? [英] If we do not support IE6, does it make sense to gzip Javascript files for IE?

查看:229
本文介绍了如果我们不支持IE6,gzip Javascript文件是否有用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果浏览器允许压缩,我正在使用Django GZip中间件(django.middleware.gzip.GZipMiddleware)来压缩内容。



如果浏览器是Internet Explorer( MSIE),内容是一个Javascript文件,那么中间件不会gzip的内容。我的理解是,在这种情况下,中间件避免了压缩,因为IE6(无补丁)对gzipped响应有问题。



对于我们的网站,我们不支持IE6,但是支持IE7和IE8。考虑到我们不支持IE6,那么即使浏览器是IE,我们也可以将所有的javascript文件都压缩成最佳实践?



如果是这样,最好的方法是什么获取这些文件gzip压缩?我们希望继续使用Django中间件模块进行gzip。我们应该制作gzip中间件模块的副本,并编辑处理IE和Javascript的几行(这感觉我们会违反DRY)?使用Apache for gzip也是一个选项。

解决方案

受JS / CSS上gzip问题影响的IE6版本不是更长的共同流通(甚至是当时的少数情况)。 Netscape 4很长,很久没有了。



因此,我强烈建议您删除所有现存的User-Agent-sniffing gzip hacks 。发送压缩的HTML / JS / CSS到请求它的所有浏览器(使用 Accept-Encoding ),按照标准HTTP / 1.1。

 如果请求中的msie.META.get('HTTP_USER_AGENT','').lower():
pre>

哦,亲爱的即使是UA嗅觉令人沮丧的标准,这是一个非常糟糕的测试。没有检查它在字符串正确的位置实际上是 MSIE (与所有尾随位置的任何位置相反,容易得到假阳性),并且不检查对于gzip测试传统的 SV1 (因为IE6SP2 +版本不会受到错误的影响),所以它打破了所有 IE的压缩只是不必要的。



它也不设置 Vary:User-Agent ,所以代理将缓存错误的版本。而且在不使用 Content-Encoding 时,为IE设置 Vary:Accept-Encoding ,所以它会在IE中打破缓存


我们应该制作一个gzip中间件模块的副本,并编辑处理IE和Javascript的几行像我们会违反DRY)?


你可以,也可以将补丁提交给Django。因为他们目前的做法是简单地破坏了。


使用Apache的gzip也是一个选择。


<是的,如果你有Apache上游,那么(例如,使用 mod_deflate )。如果您可以使用它来提供静态文件(如脚本)效率最高。 (尝试将JS保存在静态脚本中,而不是生成/模板化。)



再次,不要使用 mod_deflate 页面提到的浏览器嗅探规则。他们是脆弱和丑陋的,并试图围绕在过去十年中影响没有人的Netscape问题。


I am using the Django GZip middleware (django.middleware.gzip.GZipMiddleware) to compress content if the browser allows compression.

If the browser is Internet Explorer (MSIE) and the content is a Javascript file, then the middleware does not gzip the content. My understanding is that the middleware avoids compressing in this case because IE6 (without patches) has issues with gzipped responses.

For our site, we do not support IE6, but we do support IE7 and IE8. Considering that we do not support IE6, would it be best practice for us to gzip all javascript files even if the browser is IE?

If so, what is the best approach for getting these files gzipped? We would like to continue to use a Django middleware module for gzip. Should we make a copy of the gzip middleware module and edit the few lines that deal with IE and Javascript (this feels like we would be violating DRY)? Using Apache for gzip is also an option.

解决方案

Versions of IE6 that are affected by problems with gzip on JS/CSS are no longer in common circulation (and were a minority case even at the time). And Netscape 4 is long, long gone.

For this reason I would strongly recommend removing all extant User-Agent-sniffing gzip hacks. Send compressed HTML/JS/CSS to all browsers that request it (with Accept-Encoding), as per standard HTTP/1.1.

if "msie" in request.META.get('HTTP_USER_AGENT', '').lower():

Oh dear. That's a really poor test even by UA-sniffing's dismal standards. No checking that it's actually MSIE in the right place in the string (as opposed to anywhere in all the trailing bits; easy to get false positives), and it doesn't check for SV1 which was traditional for the gzip test (as IE6SP2+ versions cannot be affected by the bug), so it breaks compression for all IE which is just unnecessary.

It also doesn't set Vary: User-Agent, so proxies will cache the wrong version. And it sets Vary: Accept-Encoding for IE when not using Content-Encoding, so it'll break cacheing in IE.

Should we make a copy of the gzip middleware module and edit the few lines that deal with IE and Javascript (this feels like we would be violating DRY)?

You could, and maybe submit the patch to Django. Because their current approach is IMO simply broken.

Using Apache for gzip is also an option.

Yes, if you've got Apache upstream definitely use that (eg. with mod_deflate). It's most efficient if you can use it to serve static files like scripts too. (Try to keep your JS in static scripts rather than generating/templating on-the-fly.)

Again, don't use the browser-sniffing rules mentioned on the mod_deflate page. They're fragile and ugly, and are trying to code around a Netscape problem that has affected no-one in the last decade.

这篇关于如果我们不支持IE6,gzip Javascript文件是否有用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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