addHTML('I AM A PAGELET WITH RED BACKGROUND');
$PageletRed->addCSS('static/red.php');
$PageletRed->addJS('static/delayJS.php?red');
$PageletRed->addJSCode("document.getElementById('red').innerHTML += ' [JS executed]';document.getElementById('red').style.borderRadius = '30px';");
#===============================================================================
# Pagelet with blue background color
#===============================================================================
$PageletBlue = new BigPipe\DemoPagelet('customPageletID', BigPipe\Pagelet::PRIORITY_HIGH);
$PageletBlue->addHTML('I AM A PAGELET WITH BLUE BACKGROUND');
$PageletBlue->addCSS('static/blue.php');
$PageletBlue->addJS('static/delayJS.php?blue');
$PageletBlue->addJSCode("document.getElementById('blue').innerHTML += ' [JS executed]';document.getElementById('blue').style.borderRadius = '30px';");
#===============================================================================
# Pagelet with green background color
#===============================================================================
$PageletGreen = new BigPipe\DemoPagelet();
$PageletGreen->addHTML('I AM A PAGELET WITH GREEN BACKGROUND');
$PageletGreen->addCSS('static/green.php');
$PageletGreen->addJS('static/delayJS.php?green');
$PageletGreen->addJSCode("document.getElementById('green').innerHTML += ' [JS executed]';document.getElementById('green').style.borderRadius = '30px';");
?>
BigPipe Demo
BigPipe Demo
You see on this page 3 pagelets are getting rendered. Each pagelet has his own CSS and JS resources. The CSS resources change the background color of the pagelet (so you can see the effect when the CSS is loaded). The next step is to load the JS resources and they change the border-radius of the pagelet. After the loading of CSS and JS resources the static JS callback get executed. Additionally, the PhaseDoneJS callbacks performed for each pagelet phase. See the javascript console for more debug informations.
PhaseDoneJS is a new feature of BigPipe which can execute JS callbacks for each pagelet phase. Each pagelet can have multiple PhaseDoneJS callbacks for each phase. The difference between a PhaseDoneJS callback and a static JS callback ("JS_CODE") is the following: The static JS callback always get executed (regardless of whether the pipeline is enabled or disabled) and can be a main part of the JS from the pagelet. But the PhaseDoneJS callbacks are only executed if the pipeline is enabled. They are suitable for application-specific stuff.
Notice: BigPipe may support the features of the new PHP 7 in the future and you may also benefit from the performance boost with PHP 7.
Check if output flushing works on your server:
output-flushing-test.php