Defines the BigPipe placeholder strategy, to send HTML in chunks.
First: the BigPipe placeholder strategy only activates if the current request is associated with a session. Without a session, it is assumed this response is not actually dynamic: if none of the placeholders show session-dependent information, then none of the placeholders are uncacheable or poorly cacheable, which means the Page Cache (for anonymous users) can deal with it. In other words: BigPipe works for all authenticated users and for anonymous users that have a session (typical example: a shopping cart).
(This is the default, and other modules can subclass this placeholder strategy to have different rules for enabling BigPipe.)
The BigPipe placeholder strategy actually consists of two substrategies, depending on whether the current session is in a browser with JavaScript enabled or not: 1. with JavaScript enabled: #attached[big_pipe_js_placeholders]. Their replacements are streamed at the end of the page: chunk 1 is the entire page until the closing </body> tag, chunks 2 to (N-1) are replacement values for the placeholders, chunk N is </body> and everything after it. 2. with JavaScript disabled: #attached[big_pipe_nojs_placeholders]. Their replacements are streamed in situ: chunk 1 is the entire page until the first no-JS BigPipe placeholder, chunk 2 is the replacement for that placeholder, chunk 3 is the chunk from after that placeholder until the next no-JS BigPipe placeholder, et cetera.
JS BigPipe placeholders are preferred because they result in better perceived performance: the entire page can be sent, minus the placeholders. But it requires JavaScript.
No-JS BigPipe placeholders result in more visible blocking: only the part of the page can be sent until the first placeholder, after it is rendered until the second, et cetera. (In essence: multiple flushes.)
Finally, both of those substrategies can also be combined: some placeholders live in places that cannot be efficiently replaced by JavaScript, for example CSRF tokens in URLs. Using no-JS BigPipe placeholders in those cases allows the first part of the page (until the first no-JS BigPipe placeholder) to be sent sooner than when they would be replaced using SingleFlushStrategy, which would prevent anything from being sent until all those non-HTML placeholders would have been replaced.
See \Drupal\big_pipe\Render\BigPipe for detailed documentation on how those different placeholders are actually replaced.
Hierarchy
- class \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy implements PlaceholderStrategyInterface
See also
\Drupal\big_pipe\Render\BigPipeInterface
File
- core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php, line 60
Namespace
Drupal\big_pipe\Render\Placeholder
Members
Name | Modifiers | Type | Description |
---|---|---|---|
BigPipeStrategy::$requestStack | protected | property | The request stack. |
BigPipeStrategy::$routeMatch | protected | property | The current route match. |
BigPipeStrategy::$sessionConfiguration | protected | property | The session configuration. |
BigPipeStrategy::createBigPipeJsPlaceholder | protected static | function | Creates a BigPipe JS placeholder. |
BigPipeStrategy::createBigPipeNoJsPlaceholder | protected static | function | Creates a BigPipe no-JS placeholder. |
BigPipeStrategy::doProcessPlaceholders | protected | function | Transforms placeholders to BigPipe placeholders, either no-JS or JS. |
BigPipeStrategy::generateBigPipePlaceholderId | protected static | function | Generates a BigPipe placeholder ID. |
BigPipeStrategy::NOJS_COOKIE | constant | BigPipe no-JS cookie name. | |
BigPipeStrategy::processPlaceholders | public | function | Processes placeholders to render them with different strategies. Overrides PlaceholderStrategyInterface::processPlaceholders |
BigPipeStrategy::__construct | public | function | Constructs a new BigPipeStrategy class. |
Please login to continue.