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('<script>function flushHTML(id, html) {'
+ 'document.getElementById(' + id + ').innerHTML = ' + html
+ '};</script>')
// more stuff
// a "pagelet"
res.write('<script>flushHTML(' + someID + ', ' + myHTML + ');</script>')
res.end('</body></html>')
Why can't you just res.write(html)
each section without flushing?
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: