事情要注意与内容编码:gzip [英] Things to watch out for with Content-Encoding: gzip

查看:302
本文介绍了事情要注意与内容编码:gzip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了托管在S3存储一个静态的网站。我的资源文件(CSS和JS文件)的精缩和COM pressed用gzip。文件名本身可以是 file_gz.js file_gz.css ,并附带了一个内容-Encoding:GZIP

I've created a static website that is hosted on a S3 Bucket. My asset files (css and js files) are minified and compressed with gzip. The filename itself is either file_gz.js or file_gz.css and is delivered with a Content-Encoding: gzip header.

到目前为止,我已经测试了在各种浏览器的网站,并能正常工作。资产交付与他们融为一体pressed版本和网页不看有什么不同。

So far, I've tested out the website on various browsers and it works fine. The assets are delivered with their compressed versions and the page doesn't look any different.

这是我看到的唯一的问题是,因为这是一个S3桶,没有故障保护的时候,客户端(浏览器)不支持gzip编码。相反,HTTP请求将失败,并且不会有任何的造型或JavaScript,增强应用到页面。

The only issue that I see is that since this is a S3 bucket, there is no failsafe for when the the client (the browser) doesn't support the gzip encoding. Instead the HTTP request will fail and there will be no styling or javascript-enhancements applied to the page.

有谁知道的任何问题,通过设置内容编码:gzip ?是不是所有的浏览器都支持这正常吗?是否有我需要追加,使这项工作正确任何其他头?

Does anyone know of any problems by setting Content-Encoding: gzip? Do all browsers support this properly? Are there any other headers that I need to append to make this work properly?

推荐答案

现代浏览器全线支持EN codeD的内容pretty的多。但是,这不是安全的假设,所有的用户代理的意愿。您的实现的问题在于,它完全忽略HTTP的内置,避免这一非常问题的方法:内容协商的。你有两个选择:

Modern browsers support encoded content pretty much across the board. However, it's not safe to assume that all user agents will. The problem with your implementation is that it completely ignores HTTP's built-in method for avoiding this very problem: content negotiation. You have a couple of options:

  1. 您可以继续闭上眼​​睛的问题和希望的每次的用户访问你的内容就可以去code您gzip的资源代理。不幸的是,这几乎肯定不会出现这种情况;浏览器是不是唯一的用户代理那里,头功能于中砂的方法来解决问题很少是一个不错的主意。

  1. You can continue to close your eyes to the problem and hope that every user agent that accesses your content will be able to decode your gzip resources. Unfortunately, this will almost certainly not be the case; browsers are not the only user-agents out there and the "head-in-the-sand" approach to problem solving is rarely a good idea.

实施解决方案协商您是否满足使用接受编码头一个gzip压缩的响应。如果客户根本不指定此头或指定,但没有提到GZIP,你可以相当肯定,用户将不能够去codeA gzip压缩的响应。在这种情况下,你需要发送uncom pressed版本。

Implement a solution to negotiate whether or not you serve a gzipped response using the Accept-Encoding header. If the client does not specify this header at all or specifies it but doesn't mention gzip, you can be fairly sure the user won't be able to decode a gzipped response. In those cases you need to send the uncompressed version.

内容协商的来龙去脉超出了这个答案的范围。你需要做如何解析一些研究,接受编码头和洽谈您回应的编码。通常情况下,内容编码是通过使用第三方的模块,如Apache的mod_deflate模块来完成。虽然我不熟悉的S3的方案在这方面,我怀疑你需要自己实现谈判。

The ins and outs of content negotiation are beyond the scope of this answer. You'll need to do some research on how to parse the Accept-Encoding header and negotiate the encoding of your responses. Usually, content encoding is accomplished through the use of third-party modules like Apache's mod_deflate. Though I'm not familiar with S3's options in this area, I suspect you'll need to implement the negotiation yourself.

在总结:发送连接$ C $镉含量不先与客户结算这不是一个很好的主意

这篇关于事情要注意与内容编码:gzip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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