function BigPipe::sendContent
Same name in other branches
- 9 core/modules/big_pipe/src/Render/BigPipe.php \Drupal\big_pipe\Render\BigPipe::sendContent()
- 8.9.x core/modules/big_pipe/src/Render/BigPipe.php \Drupal\big_pipe\Render\BigPipe::sendContent()
- 10 core/modules/big_pipe/src/Render/BigPipe.php \Drupal\big_pipe\Render\BigPipe::sendContent()
Sends an HTML response in chunks using the BigPipe technique.
@internal This method should only be invoked by \Drupal\big_pipe\Render\BigPipeResponse, which is itself an internal class.
Parameters
\Drupal\big_pipe\Render\BigPipeResponse $response: The BigPipe response to send.
File
-
core/
modules/ big_pipe/ src/ Render/ BigPipe.php, line 225
Class
- BigPipe
- Service for sending an HTML response in chunks (to get faster page loads).
Namespace
Drupal\big_pipe\RenderCode
public function sendContent(BigPipeResponse $response) {
$content = $response->getContent();
$attachments = $response->getAttachments();
// First, gather the BigPipe placeholders that must be replaced.
$placeholders = $attachments['big_pipe_placeholders'] ?? [];
$nojs_placeholders = $attachments['big_pipe_nojs_placeholders'] ?? [];
// BigPipe sends responses using "Transfer-Encoding: chunked". To avoid
// sending already-sent assets, it is necessary to track cumulative assets
// from all previously rendered/sent chunks.
// @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41
$cumulative_assets = AttachedAssets::createFromRenderArray([
'#attached' => $attachments,
]);
$cumulative_assets->setAlreadyLoadedLibraries($attachments['library']);
// Find the closing </body> tag and get the strings before and after. But be
// careful to use the latest occurrence of the string "</body>", to ensure
// that strings in inline JavaScript or CDATA sections aren't used instead.
$parts = explode('</body>', $content);
$post_body = array_pop($parts);
$pre_body = implode('', $parts);
$this->sendPreBody($pre_body, $nojs_placeholders, $cumulative_assets);
$this->sendPlaceholders($placeholders, $this->getPlaceholderOrder($pre_body, $placeholders), $cumulative_assets);
$this->sendPostBody($post_body);
$this->performPostSendTasks();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.