另外,不应该是先gzip
filter,然后chunked filter。浏览器理应得到所有的chunked再解压的呀。。==就像zip文件的一部分不可以单独解压一样。
Hello!
2013/10/15 yurnerola:
> 1. chunked 分块传输到浏览器,可以先把 css 传输给浏览器然后让浏览器进行 css
的下载,跟内容的加载并行,提高显示速度
是的,这是常用的网页优化方法。
> 2. 目前搜索到的资料显示,如果chunked和 gzip一起用,那么浏览器也是得到所有的 chunk
之后,再进行解压,才能进行解析
>
与其相信网上随便搜索到的资料,还不如自己进行测试 :)
考虑下面这个很简单的例子:
http {
gzip on;
gzip_min_length 1;
server {
listen
8080;
location
= /t {
default_type text/html;
content_by_lua '
local rep = string.rep
local say = ngx.say
local sleep = ngx.sleep
local flush = ngx.flush
for i = 1, 10 do
say(rep("hello world", 20))
say(rep("=", 80))
flush(true)
sleep(1)
end
';
}
}
}
在这个例子里,我们每隔 1 秒钟就刷出去一段文本。我们同时启用了 nginx 的 gzip 压缩。
使用 curl 7.24.0, Firefox 22.0, 和 Chrome 30.0 都可以实时地解压并显示每一段输出。
我在测试时,curl 传入了 --compressed 选项,从而启用 gzip 压缩。而在 Firefox 和 Chrome
中都通过工具确认了响应体确实是经过压缩的 :)
值得一提的是,我的这个例子至少需要 1.5.3 以上版本的 nginx 才能正确工作。因为之前的版本里的标准的 ngx_gzip
模块有一个
bug,最早是在 1.5.3 里修复的。对应的官方补丁在这里:
http://hg.nginx.org/nginx/rev/84155a389bcc
> 问题:
> 如果 chunked 和 gzip 一起使用的时候,还能够实现 1 那样的功能么?
当然可以。上面我已经给出了一个测试过的实例 :)
> 原理是? 目前资料比较少 还没得到较好的解释。
原理很简单:gzip 压缩和解压本来就是支持按数据块进行流式处理的 :)
Best regards,
-agentzh
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 openresty@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程:
http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html