diff options
-rw-r--r-- | include/classes/BigPipe/BigPipe.php | 12 | ||||
-rw-r--r-- | static/bigpipe.js | 27 |
2 files changed, 24 insertions, 15 deletions
diff --git a/include/classes/BigPipe/BigPipe.php b/include/classes/BigPipe/BigPipe.php index c5f33e3..6e4c7f4 100644 --- a/include/classes/BigPipe/BigPipe.php +++ b/include/classes/BigPipe/BigPipe.php @@ -42,13 +42,9 @@ class BigPipe { #=============================================================================== # Prints a single pagelet response #=============================================================================== - private static function singleResponse(Pagelet $Pagelet, $last = FALSE) { + private static function singleResponse(Pagelet $Pagelet) { $pageletJSON = $Pagelet->getStructure(); - if($last) { - $pageletJSON['IS_LAST'] = TRUE; - } - $pageletHTML = removeLineBreaksAndTabs($Pagelet->getHTML()); $pageletHTML = str_replace('--', '--', $pageletHTML); @@ -100,11 +96,15 @@ class BigPipe { } else { - self::singleResponse($Pagelet, (count(self::$pagelets) === ++$i)); + self::singleResponse($Pagelet); self::flushOutputBuffer(); } } } + + if(BigPipe::enabled()) { + echo "<script>BigPipe.onLastPageletArrived();</script>\n"; + } } } ?>
\ No newline at end of file diff --git a/static/bigpipe.js b/static/bigpipe.js index ae15935..86d1cbe 100644 --- a/static/bigpipe.js +++ b/static/bigpipe.js @@ -270,6 +270,7 @@ BigPipe = (function() { phase: 0, done: [], wait: [], + interval: null, onPageletArrive(data, codeContainer) { let pageletHTML = codeContainer.innerHTML; @@ -284,10 +285,6 @@ BigPipe = (function() { this.phase = 1; } - if(data.IS_LAST) { - this.phase = 2; - } - if(pagelet.NEED.length === 0 || pagelet.NEED.every(function(needID) { return BigPipe.done.indexOf(needID) !== -1; })) { @@ -299,6 +296,17 @@ BigPipe = (function() { } }, + onLastPageletArrived() { + this.phase = 2; + + this.interval = setInterval(() => { + if(this.done.length === this.pagelets.length) { + clearInterval(this.interval); + this.executeJavascriptResources(); + } + }, 50); + }, + onPageletHTMLreplaced(pageletID) { BigPipe.done.push(pageletID); @@ -314,11 +322,6 @@ BigPipe = (function() { pagelet.execute(); } } - - // Check if this was the last pagelet and then execute loading of the external JS resources - if(BigPipe.phase === 2 && BigPipe.done.length === BigPipe.pagelets.length) { - BigPipe.executeJavascriptResources(); - } }, executeJavascriptResources() { @@ -340,6 +343,10 @@ BigPipe = (function() { BigPipe.onPageletArrive(data, codeContainer); }, + onLastPageletArrived() { + BigPipe.onLastPageletArrived(); + }, + reset() { BigPipe.pagelets.forEach(function(pagelet) { pagelet.resources[Resource.TYPE_STYLESHEET].forEach(function(resource) { @@ -357,6 +364,8 @@ BigPipe = (function() { document.execCommand('Stop'); } + clearInterval(BigPipe.interval); + BigPipe.pagelets = []; BigPipe.phase = 0; BigPipe.wait = []; |