We have released our open BigPipe implementation written for IRC-Galleria which is implemented by loosely following this facebook blog. The sources are located at github: https://github.com/garo/bigpipe and there’s an example demonstrating the library in action at http://www.juhonkoti.net/bigpipe.
BigPipe allows speeding up page rendering times by loading the page in small parts called pagelets. This allows browser to start rendering the page while the php server is still processing to finish the rest. This transforms the traditional page rendering cycle into a streaming pipeline containing the following steps:
- Browser requests the page from server
- Server quickly renders a page skeleton containing the <head> tags and a body with empty div elements which act as containers to the pagelets. The HTTP connection to the browser stays open as the page is not yet finished.
- Browser will start downloading the bigpipe.js file and after that it’ll start rendering the page
- The PHP server process is still executing and its building each pagelet at a time. Once a pagelet has been completed it’s results are sent to the browser inside a <script>BigPipe.onArrive(…)</script> tag.
- Browser injects the html code received into the correct place. If the pagelet needs any CSS resources those are also downloaded.
There’s an usage example in example.php. Take a good look on it. The example uses a lot of whitespace padding to saturate web server and browser caches so that the bigpipe loading effect is clearly visible. Of course these paddings are not required in real usage. There’s still some optimizations to be done and the implementation is way from being perfect, but that hasn’t stopped us from using this in production.
- h_bigpipe.inc BigPipe class php file
- h_pagelet.inc Pagelet class php file
- example.php Example showing how to use bigpipe
- test.js Support file for example
- test2.js Support file for example
- Browser.php Browser detection library by Chris Schuld (http://chrisschuld.com/)
- prototype.js Prototypejs.org library
- prototypepatch.js Patches for prototype