综合技术

why are “flushes” required for bigpipe?

微信扫一扫,分享到朋友圈

why are “flushes” required for bigpipe?
0

https://github.com/jehrhardt/bigpipe-node/blob/master/app.js
http://www.subbu.org/blog/2010/07/bigpipe-done-in-node-js

I’ve noticed that all implementations of bigpipe need to “flush” the HTML. In other words, something like this always happens:

// header n stuff

res.write('function flushHTML(id, html) {'
  + 'document.getElementById(' + id + ').innerHTML = ' + html
  + '};')

// more stuff

// a "pagelet"
res.write('flushHTML(' + someID + ', ' + myHTML + ');')

res.end('')

Why can’t you just res.write(html)
each section without flushing?

Problem courtesy of: Jonathan Ong

Solution

The whole point is to split big task of generating entire HTML into many small tasks ( aka pagelets ). For example assume you want to send to a browser two things: user details and details of a transaction he just made. Instead of doing both these tasks ( ie loading data from DB ) and sending HTML after that, you would load a user from DB an send it to browser, then load transaction from DB and send it to browser.

This ultimetly leads to a better user experience and faster loading time ( because browser generates HTML chunk by chunk which is more efficient then everything at once ).

Note that this was developed ( or at least widely used by ) Facebook, so read this article for more info:

http://www.facebook.com/note.php?note_id=389414033919

Solution courtesy of: freakish

阅读原文...


微信扫一扫,分享到朋友圈

why are “flushes” required for bigpipe?
0

Node.js Recipes

UX案例研究:谷歌地图 VS Waze移动应用

上一篇

SparkSql学习笔记(包含IDEA编写的本地代码)

下一篇

评论已经被关闭。

插入图片

热门分类

往期推荐

why are “flushes” required for bigpipe?

长按储存图像,分享给朋友