diff --git a/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php b/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php
index 7d36b51..69a8f13 100644
--- a/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php
+++ b/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php
@@ -148,6 +148,16 @@ protected function buildAttachmentsCommands(AjaxResponse $response, Request $req
     $css_assets = $this->assetResolver->getCssAssets($assets, $optimize_css);
     list($js_assets_header, $js_assets_footer) = $this->assetResolver->getJsAssets($assets, $optimize_js);
 
+    // First, AttachedAssets::setLibraries() ensures duplicate libraries are
+    // removed: it converts it to a set of libraries if necessary. Second,
+    // AssetResolver::getJsSettings() ensures $assets contains the final set of
+    // JavaScript settings. AttachmentsResponseProcessorInterface also mandates
+    // that the response it processes contains the final attachment values, so
+    // update both the 'library' and 'drupalSettings' attachments accordingly.
+    $attachments['library'] = $assets->getLibraries();
+    $attachments['drupalSettings'] = $assets->getSettings();
+    $response->setAttachments($attachments);
+
     // Render the HTML to load these files, and add AJAX commands to insert this
     // HTML in the page. Settings are handled separately, afterwards.
     $settings = [];
diff --git a/core/lib/Drupal/Core/Asset/AssetResolver.php b/core/lib/Drupal/Core/Asset/AssetResolver.php
index 9927049..a533c8a 100644
--- a/core/lib/Drupal/Core/Asset/AssetResolver.php
+++ b/core/lib/Drupal/Core/Asset/AssetResolver.php
@@ -334,6 +334,9 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize) {
       // Allow modules and themes to alter the JavaScript settings.
       $this->moduleHandler->alter('js_settings', $settings, $assets);
       $this->themeManager->alter('js_settings', $settings, $assets);
+      // Update the $assets object accordingly, so that it reflects the final
+      // settings.
+      $assets->setSettings($settings);
       $settings_as_inline_javascript = [
         'type' => 'setting',
         'group' => JS_SETTING,
diff --git a/core/lib/Drupal/Core/Asset/AssetResolverInterface.php b/core/lib/Drupal/Core/Asset/AssetResolverInterface.php
index c912d76..e0845c6 100644
--- a/core/lib/Drupal/Core/Asset/AssetResolverInterface.php
+++ b/core/lib/Drupal/Core/Asset/AssetResolverInterface.php
@@ -69,6 +69,8 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize);
    *
    * @param \Drupal\Core\Asset\AttachedAssetsInterface $assets
    *   The assets attached to the current response.
+   *   Note that this object is modified to reflect the final JavaScript
+   *   settings assets.
    * @param bool $optimize
    *   Whether to apply the JavaScript asset collection optimizer, to return
    *   optimized JavaScript asset collections rather than an unoptimized ones.
diff --git a/core/lib/Drupal/Core/Render/AttachmentsResponseProcessorInterface.php b/core/lib/Drupal/Core/Render/AttachmentsResponseProcessorInterface.php
index 6067a86..74614ee 100644
--- a/core/lib/Drupal/Core/Render/AttachmentsResponseProcessorInterface.php
+++ b/core/lib/Drupal/Core/Render/AttachmentsResponseProcessorInterface.php
@@ -46,7 +46,8 @@
    *   The response to process.
    *
    * @return \Drupal\Core\Render\AttachmentsInterface
-   *   The processed response.
+   *   The processed response, with the attachments updated to reflect their
+   *   final values.
    *
    * @throws \InvalidArgumentException
    *   Thrown when the $response parameter is not the type of response object
diff --git a/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php b/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php
index e0160d1..d407062 100644
--- a/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php
+++ b/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php
@@ -9,6 +9,7 @@
 use Drupal\Core\Asset\AssetCollectionRendererInterface;
 use Drupal\Core\Asset\AssetResolverInterface;
 use Drupal\Core\Asset\AttachedAssets;
+use Drupal\Core\Asset\AttachedAssetsInterface;
 use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Form\EnforcedResponseException;
 use Drupal\Core\Extension\ModuleHandlerInterface;
@@ -155,7 +156,19 @@ public function processAttachments(AttachmentsInterface $response) {
       $attachment_placeholders = $attached['html_response_attachment_placeholders'];
       unset($attached['html_response_attachment_placeholders']);
 
-      $variables = $this->processAssetLibraries($attached, $attachment_placeholders);
+      $assets = AttachedAssets::createFromRenderArray(['#attached' => $attached]);
+      // Take Ajax page state into account, to allow for something like
+      // Turbolinks to be implemented without altering core.
+      // @see https://github.com/rails/turbolinks/
+      $ajax_page_state = $this->requestStack->getCurrentRequest()->get('ajax_page_state');
+      $assets->setAlreadyLoadedLibraries(isset($ajax_page_state) ? explode(',', $ajax_page_state['libraries']) : []);
+      $variables = $this->processAssetLibraries($assets, $attachment_placeholders);
+      // $variables now contains the markup to load the asset libraries. Update
+      // $attached with the final list of libraries and JavaScript settings, so
+      // that $response can be updated with those. Then the response object will
+      // list the final, processed attachments.
+      $attached['library'] = $assets->getLibraries();
+      $attached['drupalSettings'] = $assets->getSettings();
 
       // Since we can only replace content in the HTML head section if there's a
       // placeholder for it, we can safely avoid processing the render array if
@@ -168,6 +181,7 @@ public function processAttachments(AttachmentsInterface $response) {
             $attached,
             $this->processFeed($attached['feed'])
           );
+          unset($attached['feed']);
         }
         // 'html_head_link' is a special case of 'html_head' which can be present
         // as a head element, but also as a Link: HTTP header depending on
@@ -182,6 +196,7 @@ public function processAttachments(AttachmentsInterface $response) {
             $attached,
             $this->processHtmlHeadLink($attached['html_head_link'])
           );
+          unset($attached['html_head_link']);
         }
 
         // Now we can process 'html_head', which contains both 'feed' and
@@ -200,6 +215,10 @@ public function processAttachments(AttachmentsInterface $response) {
       $this->setHeaders($response, $attached['http_header']);
     }
 
+    // AttachmentsResponseProcessorInterface mandates that the response it
+    // processes contains the final attachment values.
+    $response->setAttachments($attached);
+
     return $response;
   }
 
@@ -255,8 +274,8 @@ protected function renderPlaceholders(HtmlResponse $response) {
   /**
    * Processes asset libraries into render arrays.
    *
-   * @param array $attached
-   *   The attachments to process.
+   * @param \Drupal\Core\Asset\AttachedAssetsInterface $assets
+   *   The attached assets collection for the current response.
    * @param array $placeholders
    *   The placeholders that exist in the response.
    *
@@ -266,16 +285,7 @@ protected function renderPlaceholders(HtmlResponse $response) {
    *     - scripts
    *     - scripts_bottom
    */
-  protected function processAssetLibraries(array $attached, array $placeholders) {
-    $all_attached = ['#attached' => $attached];
-    $assets = AttachedAssets::createFromRenderArray($all_attached);
-
-    // Take Ajax page state into account, to allow for something like Turbolinks
-    // to be implemented without altering core.
-    // @see https://github.com/rails/turbolinks/
-    $ajax_page_state = $this->requestStack->getCurrentRequest()->get('ajax_page_state');
-    $assets->setAlreadyLoadedLibraries(isset($ajax_page_state) ? explode(',', $ajax_page_state['libraries']) : []);
-
+  protected function processAssetLibraries(AttachedAssetsInterface $assets, array $placeholders) {
     $variables = [];
 
     // Print styles - if present.
diff --git a/core/lib/Drupal/Core/Render/Renderer.php b/core/lib/Drupal/Core/Render/Renderer.php
index b1f7c2a..9d62dfa 100644
--- a/core/lib/Drupal/Core/Render/Renderer.php
+++ b/core/lib/Drupal/Core/Render/Renderer.php
@@ -158,24 +158,9 @@ public function renderPlain(&$elements) {
   }
 
   /**
-   * Renders final HTML for a placeholder.
-   *
-   * Renders the placeholder in isolation.
-   *
-   * @param string $placeholder
-   *   An attached placeholder to render. (This must be a key of one of the
-   *   values of $elements['#attached']['placeholders'].)
-   * @param array $elements
-   *   The structured array describing the data to be rendered.
-   *
-   * @return array
-   *   The updated $elements.
-   *
-   * @see ::replacePlaceholders()
-   *
-   * @todo Make public as part of https://www.drupal.org/node/2469431
+   * {@inheritdoc}
    */
-  protected function renderPlaceholder($placeholder, array $elements) {
+  public function renderPlaceholder($placeholder, array $elements) {
     // Get the render array for the given placeholder
     $placeholder_elements = $elements['#attached']['placeholders'][$placeholder];
 
@@ -196,7 +181,6 @@ protected function renderPlaceholder($placeholder, array $elements) {
     return $elements;
   }
 
-
   /**
    * {@inheritdoc}
    */
@@ -647,6 +631,8 @@ protected function setCurrentRenderContext(RenderContext $context = NULL) {
    *
    * @returns bool
    *   Whether placeholders were replaced.
+   *
+   * @see ::renderPlaceholder()
    */
   protected function replacePlaceholders(array &$elements) {
     if (!isset($elements['#attached']['placeholders']) || empty($elements['#attached']['placeholders'])) {
diff --git a/core/lib/Drupal/Core/Render/RendererInterface.php b/core/lib/Drupal/Core/Render/RendererInterface.php
index ff04d86..ccbe2d5 100644
--- a/core/lib/Drupal/Core/Render/RendererInterface.php
+++ b/core/lib/Drupal/Core/Render/RendererInterface.php
@@ -67,6 +67,24 @@ public function renderRoot(&$elements);
   public function renderPlain(&$elements);
 
   /**
+   * Renders final HTML for a placeholder.
+   *
+   * Renders the placeholder in isolation.
+   *
+   * @param string $placeholder
+   *   An attached placeholder to render. (This must be a key of one of the
+   *   values of $elements['#attached']['placeholders'].)
+   * @param array $elements
+   *   The structured array describing the data to be rendered.
+   *
+   * @return array
+   *   The updated $elements.
+   *
+   * @see ::render()
+   */
+  public function renderPlaceholder($placeholder, array $elements);
+
+  /**
    * Renders HTML given a structured array tree.
    *
    * Renderable arrays have two kinds of key/value pairs: properties and
diff --git a/core/modules/big_pipe/big_pipe.info.yml b/core/modules/big_pipe/big_pipe.info.yml
new file mode 100644
index 0000000..b0f6e91
--- /dev/null
+++ b/core/modules/big_pipe/big_pipe.info.yml
@@ -0,0 +1,6 @@
+name: BigPipe
+type: module
+description: 'Enables BigPipe for authenticated users; first send+render the cheap parts of the page, then the expensive parts.'
+package: Core
+version: VERSION
+core: 8.x
diff --git a/core/modules/big_pipe/big_pipe.libraries.yml b/core/modules/big_pipe/big_pipe.libraries.yml
new file mode 100644
index 0000000..88ecff6
--- /dev/null
+++ b/core/modules/big_pipe/big_pipe.libraries.yml
@@ -0,0 +1,11 @@
+big_pipe:
+  version: VERSION
+  js:
+    js/big_pipe.js: {}
+  drupalSettings:
+    bigPipePlaceholders: []
+  dependencies:
+    - core/jquery
+    - core/drupal
+    - core/drupal.ajax
+    - core/drupalSettings
diff --git a/core/modules/big_pipe/big_pipe.module b/core/modules/big_pipe/big_pipe.module
new file mode 100644
index 0000000..f2615e6
--- /dev/null
+++ b/core/modules/big_pipe/big_pipe.module
@@ -0,0 +1,56 @@
+<?php
+
+/**
+ * @file
+ * Enables BigPipe for authenticated users; first send+render the cheap parts
+ * of the page, then the expensive parts.
+ *
+ * BigPipe allows to send a page in chunks. First the main content is sent and
+ * then uncacheable data that takes long to generate.
+ */
+
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Render\Markup;
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ */
+function big_pipe_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
+  // Check if the user has JavaScript enabled without adding JavaScript.
+  $form['big_pipe_has_js'] = array(
+    '#type' => 'hidden',
+    '#default_value' => '1',
+  );
+
+  $form['#after_build'][] = 'big_pipe_form_after_build';
+  $form['#submit'][] = 'big_pipe_form_set_js_check';
+}
+
+/**
+ * After build handler for user_login_form().
+ */
+function big_pipe_form_after_build($form, FormStateInterface $form_state) {
+  // This is tricky: we want Form API to 'default big_pipe_has_js' to '1' in
+  // case it is not sent. We also want to set the value of the HTML element
+  // to '0' and wrap it in a <noscript> tag.
+  // So in case the user has JavaScript disabled, the <noscript> is parsed and
+  // 'big_pipe_has_js' is sent with '0', else it is not sent and Form API falls
+  // back to the default value, which is '1'.
+  $form['big_pipe_has_js']['#value'] = '0';
+  $form['big_pipe_has_js']['#prefix'] = Markup::create('<noscript>');
+  $form['big_pipe_has_js']['#suffix'] = Markup::create('</noscript>');
+  return $form;
+}
+
+/**
+ * Form submission handler for user_login_form().
+ *
+ * Remember whether the user has JavaScript enabled in this session.
+ */
+function big_pipe_form_set_js_check($form, FormStateInterface $form_state) {
+  $current_user = \Drupal::currentUser();
+
+  if ($current_user->isAuthenticated()) {
+    $_SESSION['big_pipe_has_js'] = $form_state->getValue('big_pipe_has_js') == 1;
+  }
+}
diff --git a/core/modules/big_pipe/big_pipe.services.yml b/core/modules/big_pipe/big_pipe.services.yml
new file mode 100644
index 0000000..d93b9c7
--- /dev/null
+++ b/core/modules/big_pipe/big_pipe.services.yml
@@ -0,0 +1,20 @@
+services:
+  html_response.big_pipe_subscriber:
+    class: Drupal\big_pipe\EventSubscriber\HtmlResponseBigPipeSubscriber
+    tags:
+      - { name: event_subscriber }
+    arguments: ['@big_pipe']
+  placeholder_strategy.big_pipe:
+    class: Drupal\big_pipe\Render\Placeholder\BigPipeStrategy
+    tags:
+      - { name: placeholder_strategy, priority: 0 }
+    arguments: ['@current_user']
+  big_pipe:
+    class: Drupal\big_pipe\Render\BigPipe
+    arguments: ['@renderer', '@session', '@request_stack', '@http_kernel', '@event_dispatcher']
+  html_response.attachments_processor.big_pipe:
+    public: false
+    class: \Drupal\big_pipe\Render\BigPipeResponseAttachmentsProcessor
+    decorates: html_response.attachments_processor
+    decoration_inner_name: html_response.attachments_processor.original
+    arguments: ['@html_response.attachments_processor.original', '@asset.resolver', '@config.factory', '@asset.css.collection_renderer', '@asset.js.collection_renderer', '@request_stack', '@renderer', '@module_handler']
diff --git a/core/modules/big_pipe/js/big_pipe.js b/core/modules/big_pipe/js/big_pipe.js
new file mode 100644
index 0000000..e21df03
--- /dev/null
+++ b/core/modules/big_pipe/js/big_pipe.js
@@ -0,0 +1,92 @@
+/**
+ * @file
+ * Provides Ajax page updating via BigPipe.
+ */
+
+(function ($, Drupal, drupalSettings) {
+
+  'use strict';
+
+  /**
+   * Execute Ajax commands included in the script tag.
+   *
+   * @param {number} index
+   *   Current index.
+   * @param {HTMLScriptElement} placeholder
+   *   Script tag created by bigPipe.
+   */
+  function bigPipeProcessPlaceholder(index, placeholder) {
+    var placeholderName = this.getAttribute('data-big-pipe-placeholder');
+    var content = this.textContent.trim();
+    // Ignore any placeholders that are not in the known placeholder list.
+    // This is used to avoid someone trying to XSS the site via the
+    // placeholdering mechanism.;
+    if (typeof drupalSettings.bigPipePlaceholders[placeholderName] !== 'undefined') {
+      // If we try to parse the content too early textContent will be empty,
+      // making JSON.parse fail. Remove once so that it can be processed again
+      // later.
+      if (content === '') {
+        $(this).removeOnce('big-pipe');
+      }
+      else {
+        var response = JSON.parse(content);
+        // Use a dummy url.
+        var ajaxObject = Drupal.ajax({url: 'big-pipe/placeholder.json'});
+        ajaxObject.success(response);
+      }
+    }
+  }
+
+  /**
+   *
+   * @param {HTMLDocument} context
+   *   Main
+   *
+   * @return {bool}
+   *   Returns true when processing has been finished and a stop tag has been
+   *   found.
+   */
+  function bigPipeProcessContainer(context) {
+    // Make sure we have bigPipe related scripts before processing further.
+    if (!context.querySelector('script[data-big-pipe-event="start"]')) {
+      return false;
+    }
+
+    $(context).find('script[data-drupal-ajax-processor="big_pipe"]').once('big-pipe')
+      .each(bigPipeProcessPlaceholder);
+
+    // If we see a stop element always clear the timeout.
+    if (context.querySelector('script[data-big-pipe-event="stop"]')) {
+      if (timeoutID) {
+        clearTimeout(timeoutID);
+      }
+      return true;
+    }
+
+    return false;
+  }
+
+  function bigPipeProcess() {
+    timeoutID = setTimeout(function () {
+      if (!bigPipeProcessContainer(document)) {
+        bigPipeProcess();
+      }
+    }, interval);
+  }
+
+  var interval = 200;
+  // The internal ID to contain the watcher service.
+  var timeoutID;
+
+  bigPipeProcess();
+
+  // If something goes wrong, make sure everything is cleaned up and has had a
+  // chance to be processed with everything loaded.
+  $(window).on('load', function () {
+    if (timeoutID) {
+      clearTimeout(timeoutID);
+    }
+    bigPipeProcessContainer(document);
+  });
+
+})(jQuery, Drupal, drupalSettings);
diff --git a/core/modules/big_pipe/src/EventSubscriber/HtmlResponseBigPipeSubscriber.php b/core/modules/big_pipe/src/EventSubscriber/HtmlResponseBigPipeSubscriber.php
new file mode 100644
index 0000000..769581f
--- /dev/null
+++ b/core/modules/big_pipe/src/EventSubscriber/HtmlResponseBigPipeSubscriber.php
@@ -0,0 +1,141 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\big_pipe\EventSubscriber\HtmlResponseBigPipeSubscriber.
+ */
+
+namespace Drupal\big_pipe\EventSubscriber;
+
+use Drupal\Core\Render\HtmlResponse;
+use Drupal\big_pipe\Render\BigPipeInterface;
+use Drupal\big_pipe\Render\BigPipeResponse;
+use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+/**
+ * Response subscriber to replace the HtmlResponse with a BigPipeResponse.
+ */
+class HtmlResponseBigPipeSubscriber implements EventSubscriberInterface {
+
+  /**
+   * The BigPipe service.
+   *
+   * @var \Drupal\big_pipe\Render\BigPipeInterface
+   */
+  protected $bigPipe;
+
+  /**
+   * Constructs a HtmlResponseBigPipeSubscriber object.
+   *
+   * @param \Drupal\big_pipe\Render\BigPipeInterface $big_pipe
+   *   The BigPipe service.
+   */
+  public function __construct(BigPipeInterface $big_pipe) {
+    $this->bigPipe = $big_pipe;
+  }
+
+  /**
+   * Adds markers to the response necessary for the BigPipe render strategy.
+   *
+   * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
+   *   The event to process.
+   */
+  public function onRespondEarly(FilterResponseEvent $event) {
+    $response = $event->getResponse();
+    if (!$response instanceof HtmlResponse) {
+      return;
+    }
+
+    // Set a marker around 'scripts_bottom'
+    $attachments = $response->getAttachments();
+    if (isset($attachments['html_response_attachment_placeholders']['scripts_bottom'])) {
+      $scripts_bottom_placeholder = $attachments['html_response_attachment_placeholders']['scripts_bottom'];
+      $content = $response->getContent();
+
+      // Wrap the scripts_bottom placeholder with a marker before and after,
+      // because \Drupal\big_pipe\Render\BigPipe needs to be able to parse out
+      // that placeholder for the "HalfPipe" render strategy.
+      $content = str_replace($scripts_bottom_placeholder, '<drupal-big-pipe-scripts-bottom-marker>' . $scripts_bottom_placeholder . '<drupal-big-pipe-scripts-bottom-marker>', $content);
+      $response->setContent($content);
+    }
+  }
+
+  /**
+   * Transforms a HtmlResponse to a BigPipeResponse.
+   *
+   * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
+   *   The event to process.
+   */
+  public function onRespond(FilterResponseEvent $event) {
+    if (!$event->isMasterRequest()) {
+      return;
+    }
+
+    $response = $event->getResponse();
+    if (!$response instanceof HtmlResponse) {
+      return;
+    }
+
+    $attachments = $response->getAttachments();
+    if (empty($attachments['big_pipe_placeholders'])) {
+      // Remove our marker again.
+      $content = $response->getContent();
+      $content = str_replace('<drupal-big-pipe-scripts-bottom-marker>', '', $content);
+      $response->setContent($content);
+      return;
+    }
+
+    // Create a new Response.
+    $big_pipe_response = new BigPipeResponse();
+    $big_pipe_response->setBigPipeService($this->bigPipe);
+
+    // Clone the response.
+    $big_pipe_response->headers = clone $response->headers;
+    $big_pipe_response->setStatusCode($response->getStatusCode());
+    $big_pipe_response->setContent($response->getContent());
+    $big_pipe_response->addCacheableDependency($response->getCacheableMetadata());
+
+    // A BigPipe response can never be cached, because it is intended for a
+    // single user.
+    // @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1
+    $big_pipe_response->setPrivate();
+
+    // Inform surrogates how they should handle BigPipe responses:
+    // - "no-store" specifies that the response should not be stored in cache;
+    //   it is only to be used for the original request
+    // - "content" identifies what processing surrogates should perform on the
+    //   response before forwarding it. We send, "BigPipe/1.0", which surrogates
+    //   should not process at all, and in fact, they should not even buffer it
+    //   at all.
+    // @see http://www.w3.org/TR/edge-arch/
+    $big_pipe_response->headers->set('Surrogate-Control', 'no-store, content="BigPipe/1.0"');
+
+    // Add header to support streaming on NGINX + php-fpm (nginx >= 1.5.6).
+    $big_pipe_response->headers->set('X-Accel-Buffering', 'no');
+
+    // Set the remaining attachments.
+    $big_pipe_response->setAttachments($attachments);
+
+    // And set the new response.
+    $event->setResponse($big_pipe_response);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getSubscribedEvents() {
+    // Run after HtmlResponsePlaceholderStrategySubscriber (priority 5), i.e.
+    // after BigPipeStrategy has been applied, but before normal (priority 0)
+    // response subscribers have been applied, because by then it'll be too late
+    // to transform it into a BigPipeResponse.
+    $events[KernelEvents::RESPONSE][] = ['onRespondEarly', 3];
+
+    // Run as the last possible subscriber.
+    $events[KernelEvents::RESPONSE][] = ['onRespond', -10000];
+
+    return $events;
+  }
+
+}
diff --git a/core/modules/big_pipe/src/Render/BigPipe.php b/core/modules/big_pipe/src/Render/BigPipe.php
new file mode 100644
index 0000000..284de02
--- /dev/null
+++ b/core/modules/big_pipe/src/Render/BigPipe.php
@@ -0,0 +1,328 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\big_pipe\Render\BigPipe.
+ */
+
+namespace Drupal\big_pipe\Render;
+
+use Drupal\Component\Utility\Html;
+use Drupal\Core\Ajax\AjaxResponse;
+use Drupal\Core\Ajax\ReplaceCommand;
+use Drupal\Core\Asset\AttachedAssets;
+use Drupal\Core\Render\BubbleableMetadata;
+use Drupal\Core\Render\RendererInterface;
+use Drupal\Core\Render\AttachmentsResponseProcessorInterface;
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\RequestStack;
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
+use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
+use Symfony\Component\HttpKernel\HttpKernelInterface;
+use Symfony\Component\HttpKernel\Kernel;
+use Symfony\Component\HttpKernel\KernelEvents;
+
+/**
+ * A class that allows sending the main content first, then replace
+ * placeholders to send the rest using Javascript replacements.
+ */
+class BigPipe implements BigPipeInterface {
+
+  /**
+   * The renderer.
+   *
+   * @var \Drupal\Core\Render\RendererInterface
+   */
+  protected $renderer;
+
+  /**
+   * The session.
+   *
+   * @var \Symfony\Component\HttpFoundation\Session\SessionInterface
+   */
+  protected $session;
+
+  /**
+   * The request stack.
+   *
+   * @var \Symfony\Component\HttpFoundation\RequestStack
+   */
+  protected $requestStack;
+
+  /**
+   * The HTTP kernel.
+   *
+   * @var \Symfony\Component\HttpKernel\HttpKernelInterface
+   */
+  protected $httpKernel;
+
+  /**
+   * The event dispatcher.
+   *
+   * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
+   */
+  protected $eventDispatcher;
+
+  /**
+   * Constructs a new BigPipe class.
+   *
+   * @param \Drupal\Core\Render\RendererInterface
+   *   The renderer.
+   * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
+   *   The session.
+   * @param \Symfony\Component\HttpFoundation\RequestStack
+   *   The request stack.
+   * @param \Symfony\Component\HttpKernel\HttpKernelInterface
+   *   The HTTP kernel.
+   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
+   *   The event dispatcher.
+   */
+  public function __construct(RendererInterface $renderer, SessionInterface $session, RequestStack $request_stack, HttpKernelInterface $http_kernel, EventDispatcherInterface $event_dispatcher) {
+    $this->renderer = $renderer;
+    $this->session = $session;
+    $this->requestStack = $request_stack;
+    $this->httpKernel = $http_kernel;
+    $this->eventDispatcher = $event_dispatcher;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function sendContent($content, array $attachments) {
+    // We are sending a BigPipeResponse in this method. A BigPipeResponse is an
+    // aggregated response: it consists of a HtmlResponse plus multiple embedded
+    // AjaxResponses. The embedded AjaxResponses are generated here, in this
+    // method: one for each placeholder that needs to be replaced. This means
+    // that each AjaxResponse needs to be aware of the asset libraries that have
+    // already been loaded by the initial HtmlResponse plus all the preceding
+    // AjaxResponses. An AttachedAssetsInterface object is a perfect way to
+    // track this over time.
+    $assets = AttachedAssets::createFromRenderArray(['#attached' => $attachments]);
+    $assets->setAlreadyLoadedLibraries(explode(',', $attachments['drupalSettings']['ajaxPageState']['libraries']));
+
+    // The content in the placeholders may depend on the session, and by the
+    // time the response is sent (see index.php), the session is already closed.
+    // Reopen it for the duration that we are rendering placeholders.
+    $this->session->start();
+
+    // Extract the scripts_bottom markup; the HalfPipe render strategy needs to
+    // be able to update it.
+    $t = explode('<drupal-big-pipe-scripts-bottom-marker>', $content, 3);
+    assert('count($t) == 3', 'There is content before and after scripts_bottom.');
+    $scripts_bottom = $t[1];
+    unset($t[1]);
+    $content = implode('', $t);
+
+    // Split it up in various chunks.
+    $page_parts = explode('</body>', $content);
+    if (count($page_parts) !== 2) {
+      throw new \LogicException("You need to have only one body or one <!-- X-RENDER-CACHE-BIG-PIPE-SPLIT --> tag in your html.html.twig template file.");
+    }
+
+    $placeholders = isset($attachments['big_pipe_placeholders']) ? $attachments['big_pipe_placeholders'] : [];
+    $half_pipe_placeholders = [];
+
+    if (empty($_SESSION['big_pipe_has_js'])) {
+      $half_pipe_placeholders = $placeholders;
+      $placeholders = [];
+    }
+
+    if (!empty($half_pipe_placeholders)) {
+      $extra_attachments = $this->doHalfPipe($page_parts[0], $half_pipe_placeholders);
+      // Print the extra attachments.
+      if (!empty($extra_attachments['library']) || !empty($extra_attachments['drupalSettings'])) {
+        $all_attachments = BubbleableMetadata::mergeAttachments($attachments, $extra_attachments);
+
+        // Update the extra libraries using the Response's ajax page state.
+        // In the ideal case this will be empty and all libraries have been
+        // to the bottom js section already.
+        $variables_extra = $this->htmlResponseAttachmentsProcessor->processAssetLibraries($extra_attachments, [ 'scripts' => 'TRUE', 'styles' => TRUE ], $this->ajaxPageState);
+        if (!empty($variables_extra['styles'])) {
+          print $this->renderer->renderRoot($variables_extra['styles']);
+        }
+        if (!empty($variables_extra['styles'])) {
+          print $this->renderer->renderRoot($variables_extra['scripts']);
+        }
+
+        // Now that the placeholders have been rendered using the HalfPipe
+        // render strategy, recalculate the scripts_bottom markup.
+        $variables = $this->htmlResponseAttachmentsProcessor->processAssetLibraries($all_attachments, [ 'scripts_bottom' => TRUE ]);
+        $scripts_bottom = $this->renderer->renderRoot($variables['scripts_bottom']);
+      }
+    }
+    else {
+      print $page_parts[0];
+      ob_end_flush();
+    }
+
+    // Send the JavaScript at the bottom of the page.
+    print $scripts_bottom;
+
+    flush();
+
+    if (empty($placeholders)) {
+      print '</body>';
+      print $page_parts[1];
+      return;
+    }
+
+    // Print a container and the start signal.
+    print "\n";
+    print '<script type="application/json" data-big-pipe-event="start"></script>' . "\n";
+
+    flush();
+
+    // Sort placeholders by the order in which they appear in the markup.
+    $order = $this->getPlaceholderOrder($content);
+
+    // A BigPipe response consists of a HTML response plus multiple embedded
+    // AJAX responses. To process the attachments of those AJAX responses, we
+    // need a fake request that is identical to the master request, but with
+    // one change: it must have the right Accept header, otherwise the work-
+    // around for a bug in IE9 will cause not JSON, but <textarea>-wrapped JSON
+    // to be returned.
+    // @see \Drupal\Core\EventSubscriber\AjaxResponseSubscriber::onResponse()
+    $fake_request = $this->requestStack->getMasterRequest()->duplicate();
+    $fake_request->headers->set('Accept', 'application/json');
+
+    foreach ($order as $placeholder) {
+      if (!isset($placeholders[$placeholder])) {
+        continue;
+      }
+
+      // Check if the placeholder is present at all.
+      if (strpos($content, $placeholder) === FALSE) {
+        continue;
+      }
+
+      $placeholder_elements = $placeholders[$placeholder];
+
+      // Render the placeholder.
+      $elements = $this->renderPlaceholder($placeholder, $placeholder_elements);
+
+      // Create a new AjaxResponse.
+      $ajax_response = new AjaxResponse();
+      // JavaScript's querySelector automatically decodes HTML entities in
+      // attributes, so we must decode the entities of the current BigPipe
+      // placeholder (which has HTML entities encoded since we use it to find
+      // the placeholders).
+      $big_pipe_js_selector = Html::decodeEntities($placeholder);
+      $ajax_response->addCommand(new ReplaceCommand(sprintf('[data-big-pipe-selector="%s"]', $big_pipe_js_selector), $elements['#markup']));
+      $ajax_response->setAttachments($elements['#attached']);
+
+      // Push a fake request with the asset libraries loaded so far and dispatch
+      // KernelEvents::RESPONSE event. This results in the attachments for the
+      // AJAX response being processed by AjaxResponseAttachmentsProcessor and
+      // hence:
+      // - the necessary AJAX commands to load the necessary missing asset
+      //   libraries and updated AJAX page state are added to the AJAX response
+      // - the attachments associated with the response are finalized, which
+      //   allows us to track the total set of asset libraries sent in the
+      //   initial HTML response plus all embedded AJAX responses sent so far.
+      $fake_request->request->set('ajax_page_state', ['libraries' => implode(',', $assets->getAlreadyLoadedLibraries())] + $assets->getSettings()['ajaxPageState']);
+      $this->requestStack->push($fake_request);
+      $event = new FilterResponseEvent($this->httpKernel, $fake_request, HttpKernelInterface::SUB_REQUEST, $ajax_response);
+      $this->eventDispatcher->dispatch(KernelEvents::RESPONSE, $event);
+      $ajax_response = $event->getResponse();
+      $this->requestStack->pop();
+
+      // Send this embedded AJAX response.
+      $json = $ajax_response->getContent();
+      $output = <<<EOF
+    <script type="application/json" data-big-pipe-placeholder="$placeholder" data-drupal-ajax-processor="big_pipe">
+    $json
+    </script>
+
+EOF;
+      print $output;
+      flush();
+
+      // Another placeholder was rendered and sent, track the set of asset
+      // libraries sent so far.
+      $assets->setAlreadyLoadedLibraries(explode(',', $ajax_response->getAttachments()['drupalSettings']['ajaxPageState']['libraries']));
+    }
+
+    // Send the stop signal.
+    print '<script type="application/json" data-big-pipe-event="stop"></script>' . "\n";
+    print '</body>';
+    print $page_parts[1];
+
+    // Close the session again.
+    $this->session->save();
+
+    return $this;
+  }
+
+  /**
+   * Renders a placeholder, and just that placeholder.
+   *
+   * BigPipe renders placeholders independently of the rest of the content, so
+   * it needs to be able to render placeholders by themselves.
+   *
+   * @param string $placeholder
+   *   The placeholder to render.
+   * @param array $placeholder_elements
+   *   The render array associated with that placeholder.
+   * @return array
+   *   The render array representing the rendered placeholder.
+   *
+   * @see \Drupal\Core\Render\RendererInterface::renderPlaceholder()
+   */
+  protected function renderPlaceholder($placeholder, $placeholder_elements) {
+    $elements = [
+      '#markup' => $placeholder,
+      '#attached' => [
+        'placeholders' => [
+          $placeholder => $placeholder_elements,
+        ],
+      ],
+    ];
+    return $this->renderer->renderPlaceholder($placeholder, $elements);
+  }
+
+  protected function getPlaceholderOrder($content, $selector = '<div data-big-pipe-selector="') {
+    $fragments = explode($selector, $content);
+    array_shift($fragments);
+    $order = [];
+
+    foreach ($fragments as $fragment) {
+      $t = explode('"></div>', $fragment, 2);
+      $placeholder = $t[0];
+      $order[] = $placeholder;
+    }
+
+    return $order;
+  }
+
+  protected function doHalfPipe($content, $placeholders, $selector = '<div data-big-pipe-selector="') {
+    $fragments = explode($selector, $content);
+    print array_shift($fragments);
+    ob_end_flush();
+    flush();
+
+    $attachments = array();
+
+    foreach ($fragments as $fragment) {
+      $t = explode('"></div>', $fragment, 2);
+      $placeholder = $t[0];
+      if (!isset($placeholders[$placeholder])) {
+        continue;
+      }
+
+      // Render the placeholder.
+      $elements = $this->renderPlaceholder($placeholder, $placeholders[$placeholder]);
+      if (!empty($elements['#attached'])) {
+        $attachments = BubbleableMetadata::mergeAttachments($attachments, $elements['#attached']);
+      }
+
+      print $elements['#markup'];
+      print $t[1];
+      flush();
+    }
+
+    return $attachments;
+  }
+
+}
diff --git a/core/modules/big_pipe/src/Render/BigPipeInterface.php b/core/modules/big_pipe/src/Render/BigPipeInterface.php
new file mode 100644
index 0000000..fbcfec5
--- /dev/null
+++ b/core/modules/big_pipe/src/Render/BigPipeInterface.php
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\big_pipe\Render\BigPipeInterface.
+ */
+
+namespace Drupal\big_pipe\Render;
+
+/**
+ * An interface that allows sending the main content first, then replace
+ * placeholders to send the rest using Javascript replacements.
+ */
+interface BigPipeInterface {
+
+  /**
+   * Sends the content to the browser, splitting before the closing </body> tag
+   * and afterwards processes placeholders to send when they have been rendered.
+   *
+   * The output buffers are flushed in between.
+   *
+   * @param string $content
+   *   The response content to send.
+   * @param array $attachments
+   *   The response's attachments
+   */
+  public function sendContent($content, array $attachments);
+
+}
diff --git a/core/modules/big_pipe/src/Render/BigPipeResponse.php b/core/modules/big_pipe/src/Render/BigPipeResponse.php
new file mode 100644
index 0000000..c543ae0
--- /dev/null
+++ b/core/modules/big_pipe/src/Render/BigPipeResponse.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\big_pipe\Render\BigPipeResponse.
+ */
+
+namespace Drupal\big_pipe\Render;
+
+use Drupal\Core\Render\HtmlResponse;
+
+/**
+ * A response that allows to send placeholders after the main content has been
+ * send.
+ */
+class BigPipeResponse extends HtmlResponse {
+
+  /**
+   * An array of placeholders to process.
+   *
+   * @var array
+   */
+  protected $bigPipePlaceholders;
+
+  /**
+   * The BigPipe service.
+   *
+   * @var \Drupal\big_pipe\Render\BigPipeInterface
+   */
+  protected $bigPipe;
+
+  /**
+   * Sets the big pipe service to use.
+   *
+   * @param \Drupal\big_pipe\Render\BigPipeInterface $big_pipe
+   *   The BigPipe service.
+   */
+  public function setBigPipeService(BigPipeInterface $big_pipe) {
+    $this->bigPipe = $big_pipe;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function sendContent() {
+    $this->bigPipe->sendContent($this->content, $this->getAttachments());
+
+    return $this;
+  }
+}
diff --git a/core/modules/big_pipe/src/Render/BigPipeResponseAttachmentsProcessor.php b/core/modules/big_pipe/src/Render/BigPipeResponseAttachmentsProcessor.php
new file mode 100644
index 0000000..3e54417
--- /dev/null
+++ b/core/modules/big_pipe/src/Render/BigPipeResponseAttachmentsProcessor.php
@@ -0,0 +1,107 @@
+<?php
+/**
+ * @file
+ * Contains \Drupal\big_pipe\Render\BigPipeResponseAttachmentsProcessor.
+ */
+
+namespace Drupal\big_pipe\Render;
+
+use Drupal\Core\Asset\AssetCollectionRendererInterface;
+use Drupal\Core\Asset\AssetResolverInterface;
+use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Form\EnforcedResponseException;
+use Drupal\Core\Render\AttachmentsInterface;
+use Drupal\Core\Render\AttachmentsResponseProcessorInterface;
+use Drupal\Core\Render\HtmlResponse;
+use Drupal\Core\Render\HtmlResponseAttachmentsProcessor;
+use Drupal\Core\Render\RendererInterface;
+use Symfony\Component\HttpFoundation\RequestStack;
+
+/**
+ * Processes attachments of HTML responses with BigPipe enabled.
+ *
+ * @see \Drupal\Core\Render\HtmlResponseAttachmentsProcessor
+ * @see \Drupal\big_pipe\Render\BigPipe
+ */
+class BigPipeResponseAttachmentsProcessor extends HtmlResponseAttachmentsProcessor {
+
+  /**
+   * The HTML response attachments processor service.
+   *
+   * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface
+   */
+  protected $htmlResponseAttachmentsProcessor;
+
+  /**
+   * Constructs a BigPipeResponseAttachmentsProcessor object.
+   *
+   * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor
+   *   The HTML response attachments processor service.
+   * @param \Drupal\Core\Asset\AssetResolverInterface $asset_resolver
+   *   An asset resolver.
+   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+   *   A config factory for retrieving required config objects.
+   * @param \Drupal\Core\Asset\AssetCollectionRendererInterface $css_collection_renderer
+   *   The CSS asset collection renderer.
+   * @param \Drupal\Core\Asset\AssetCollectionRendererInterface $js_collection_renderer
+   *   The JS asset collection renderer.
+   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
+   *   The request stack.
+   * @param \Drupal\Core\Render\RendererInterface $renderer
+   *   The renderer.
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+   *   The module handler service.
+   */
+  public function __construct(AttachmentsResponseProcessorInterface $html_response_attachments_processor, AssetResolverInterface $asset_resolver, ConfigFactoryInterface $config_factory, AssetCollectionRendererInterface $css_collection_renderer, AssetCollectionRendererInterface $js_collection_renderer, RequestStack $request_stack, RendererInterface $renderer, ModuleHandlerInterface $module_handler) {
+    $this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor;
+    parent::__construct($asset_resolver, $config_factory, $css_collection_renderer, $js_collection_renderer, $request_stack, $renderer, $module_handler);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function processAttachments(AttachmentsInterface $response) {
+    // @todo Convert to assertion once https://www.drupal.org/node/2408013 lands
+    if (!$response instanceof HtmlResponse) {
+      throw new \InvalidArgumentException('\Drupal\Core\Render\HtmlResponse instance expected.');
+    }
+
+    // First, render the actual placeholders; this will cause the BigPipe
+    // placeholder strategy to generate BigPipe placeholders. We need those to
+    // exist already so that we can extract BigPipe placeholders. This is hence
+    // a bit of unfortunate but necessary duplication.
+    // @see \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy
+    // (Note this is copied verbatim from
+    // \Drupal\Core\Render\HtmlResponseAttachmentsProcessor::processAttachments)
+    try {
+      $response = $this->renderPlaceholders($response);
+    }
+    catch (EnforcedResponseException $e) {
+      return $e->getResponse();
+    }
+
+    // Extract BigPipe placeholders; HtmlResponseAttachmentsProcessor does not
+    // know (nor need to know) how to process those.
+    $attachments = $response->getAttachments();
+    $big_pipe_placeholders = [];
+    if (isset($attachments['big_pipe_placeholders'])) {
+      $big_pipe_placeholders = $attachments['big_pipe_placeholders'];
+      unset($attachments['big_pipe_placeholders']);
+    }
+    $response->setAttachments($attachments);
+
+    // Call HtmlResponseAttachmentsProcessor to process all other attachments.
+    $this->htmlResponseAttachmentsProcessor->processAttachments($response);
+
+    // Restore BigPipe placeholders.
+    $attachments = $response->getAttachments();
+    if (count($big_pipe_placeholders)) {
+      $attachments['big_pipe_placeholders'] = $big_pipe_placeholders;
+    }
+    $response->setAttachments($attachments);
+
+    return $response;
+  }
+
+}
diff --git a/core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php b/core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php
new file mode 100644
index 0000000..be75fcb
--- /dev/null
+++ b/core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php
@@ -0,0 +1,166 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy
+ */
+
+namespace Drupal\big_pipe\Render\Placeholder;
+
+use Drupal\Component\Utility\Html;
+use Drupal\Component\Utility\UrlHelper;
+use Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface;
+use Drupal\Core\Session\AccountInterface;
+
+/**
+ * Defines the BigPipe placeholder strategy, to send HTML in chunks.
+ *
+ * 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.
+ *
+ * @see \Drupal\big_pipe\Render\BigPipe
+ *
+ * @todo Rename #attached[big_pipe_placeholders] to #attached[big_pipe_js_placeholders]
+ * @todo Introduce #attached[big_pipe_nojs_placeholders] and remove the current globals-based switching logic in this class and the BigPipe class
+ */
+class BigPipeStrategy implements PlaceholderStrategyInterface {
+
+  /**
+   * The current user.
+   *
+   * @var \Drupal\Core\Session\AccountInterface
+   */
+  protected $currentUser;
+
+  /**
+   * Constructs a new BigPipeStrategy class.
+   *
+   * @param \Drupal\Core\Session\AccountInterface $current_user
+   *   The current user.
+   */
+  public function __construct(AccountInterface $current_user) {
+    $this->currentUser = $current_user;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function processPlaceholders(array $placeholders) {
+    $return = [];
+
+    // @todo Move to a ResponsePolicy instead.
+    // @todo Add user.roles:authenticated cache context.
+    if (!$this->currentUser->isAuthenticated()) {
+      return $return;
+    }
+
+    // @todo Add 'session' cache context.
+    if (empty($_SESSION['big_pipe_has_js'])) {
+      return $return;
+    }
+
+    foreach ($placeholders as $placeholder => $placeholder_elements) {
+      // BigPipe uses JavaScript and the DOM to find the placeholder to replace.
+      // This means finding the placeholder to replace must be efficient. Most
+      // placeholders are HTML, which we can find efficiently thanks to the
+      // querySelector API. But some placeholders are HTML attribute values or
+      // parts thereof, and potentially even plain text in DOM text nodes. For
+      // BigPipe's JavaScript to find those placeholders, it would need to
+      // iterate over all DOM text nodes. This is highly inefficient. Therefore,
+      // the BigPipe placeholder strategy only converts HTML placeholders into
+      // BigPipe placeholders. The other placeholders need to be replaced on the
+      // server, not via BigPipe.
+      // @see \Drupal\Core\Access\RouteProcessorCsrf::renderPlaceholderCsrfToken()
+      // @see \Drupal\Core\Form\FormBuilder::renderFormTokenPlaceholder()
+      // @see \Drupal\Core\Form\FormBuilder::renderPlaceholderFormAction()
+      if ($placeholder[0] !== '<' || $placeholder !== Html::normalize($placeholder)) {
+        // @todo Use #attached[big_pipe_nojs_placeholders] instead of skipping these altogether, that allows parts of the page to be sent faster!
+        continue;
+      }
+      else {
+        $return[$placeholder] = static::createBigPipeJsPlaceholder($placeholder, $placeholder_elements);
+      }
+    }
+
+    return $return;
+  }
+
+  /**
+   * Creates a BigPipe JS placeholder.
+   *
+   * @param string $original_placeholder
+   *   The original placeholder.
+   * @param array $placeholder_render_array
+   *   The render array for a placeholder.
+   *
+   * @return array
+   *   The resulting BigPipe JS placeholder render array.
+   */
+  protected static function createBigPipeJsPlaceholder($original_placeholder, array $placeholder_render_array) {
+    // Generate a BigPipe selector (to be used by BigPipe's JavaScript).
+    // @see \Drupal\Core\Render\PlaceholderGenerator::createPlaceholder()
+    if (isset($placeholder_render_array['#lazy_builder'])) {
+      $callback = $placeholder_render_array['#lazy_builder'][0];
+      $arguments = $placeholder_render_array['#lazy_builder'][1];
+      $token = hash('crc32b', serialize($placeholder_render_array));
+      $big_pipe_js_selector = UrlHelper::buildQuery(['callback' => $callback, 'args' => $arguments, 'token' => $token]);
+    }
+    // When the placeholder's render array is not using a #lazy_builder,
+    // anything could be in there: only #lazy_builder has a strict contract that
+    // allows us to create a more sane selector. Therefore, simply the original
+    // placeholder into a usable selector, at the cost of it being obtuse.
+    else {
+      $big_pipe_js_selector = Html::getId($original_placeholder);
+    }
+
+    return [
+      '#markup' => '<div data-big-pipe-selector="' . Html::escape($big_pipe_js_selector) . '"></div>',
+      '#cache' => [
+        'contexts' => ['session'],
+        'max-age' => 0,
+      ],
+      '#attached' => [
+        'library' => [
+          'big_pipe/big_pipe',
+        ],
+        // Inform BigPipe' JavaScript known BigPipe placeholders (a whitelist).
+        'drupalSettings' => [
+          'bigPipePlaceholders' => [$big_pipe_js_selector => TRUE],
+        ],
+        'big_pipe_placeholders' => [
+          Html::escape($big_pipe_js_selector) => $placeholder_render_array,
+        ],
+      ],
+    ];
+  }
+
+}
diff --git a/core/modules/system/src/Tests/Common/AttachedAssetsTest.php b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
index 7440d99..cc04606 100644
--- a/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
+++ b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
@@ -108,8 +108,10 @@ function testAddJsSettings() {
     $build['#attached']['library'][] = 'core/drupalSettings';
     $assets = AttachedAssets::createFromRenderArray($build);
 
+    $this->assertEqual([], $assets->getSettings(), 'JavaScript settings on $assets are empty.');
     $javascript = $this->assetResolver->getJsAssets($assets, FALSE)[1];
     $this->assertTrue(array_key_exists('currentPath', $javascript['drupalSettings']['data']['path']), 'The current path JavaScript setting is set correctly.');
+    $this->assertTrue(array_key_exists('currentPath', $assets->getSettings()['path']), 'JavaScript settings on $assets are resolved after retrieving JavaScript assets, and are equal to the returned JavaScript settings.');
 
     $assets->setSettings(['drupal' => 'rocks', 'dries' => 280342800]);
     $javascript = $this->assetResolver->getJsAssets($assets, FALSE)[1];
