Chris@0: ' . t('About') . '';
Chris@0: $output .= '
' . t('The BigPipe module sends pages with dynamic content in a way that allows browsers to show them much faster. For more information, see the online documentation for the BigPipe module.', [':big_pipe-documentation' => 'https://www.drupal.org/documentation/modules/big_pipe']) . '
';
Chris@0: $output .= '' . t('Uses') . '
';
Chris@0: $output .= '';
Chris@0: $output .= '- ' . t('Speeding up your site') . '
';
Chris@0: $output .= '- ' . t('The module requires no configuration. Every part of the page contains metadata that allows BigPipe to figure this out on its own.') . '
';
Chris@0: $output .= '
';
Chris@0:
Chris@0: return $output;
Chris@0: }
Chris@0: }
Chris@0:
Chris@0: /**
Chris@0: * Implements hook_page_attachments().
Chris@0: *
Chris@0: * @see \Drupal\big_pipe\Controller\BigPipeController::setNoJsCookie()
Chris@0: */
Chris@0: function big_pipe_page_attachments(array &$page) {
Chris@0: // Routes that don't use BigPipe also don't need no-JS detection.
Chris@0: if (\Drupal::routeMatch()->getRouteObject()->getOption('_no_big_pipe')) {
Chris@0: return;
Chris@0: }
Chris@0:
Chris@0: $request = \Drupal::request();
Chris@0: // BigPipe is only used when there is an actual session, so only add the no-JS
Chris@0: // detection when there actually is a session.
Chris@0: // @see \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy.
Chris@0: $session_exists = \Drupal::service('session_configuration')->hasSession($request);
Chris@0: $page['#cache']['contexts'][] = 'session.exists';
Chris@0: // Only do the no-JS detection while we don't know if there's no JS support:
Chris@0: // avoid endless redirect loops.
Chris@0: $has_big_pipe_nojs_cookie = $request->cookies->has(BigPipeStrategy::NOJS_COOKIE);
Chris@0: $page['#cache']['contexts'][] = 'cookies:' . BigPipeStrategy::NOJS_COOKIE;
Chris@0: if ($session_exists) {
Chris@0: if (!$has_big_pipe_nojs_cookie) {
Chris@0: // Let server set the BigPipe no-JS cookie.
Chris@0: $page['#attached']['html_head'][] = [
Chris@0: [
Chris@0: // Redirect through a 'Refresh' meta tag if JavaScript is disabled.
Chris@0: '#tag' => 'meta',
Chris@0: '#noscript' => TRUE,
Chris@0: '#attributes' => [
Chris@0: 'http-equiv' => 'Refresh',
Chris@0: 'content' => '0; URL=' . Url::fromRoute('big_pipe.nojs', [], ['query' => \Drupal::service('redirect.destination')->getAsArray()])->toString(),
Chris@0: ],
Chris@0: ],
Chris@0: 'big_pipe_detect_nojs',
Chris@0: ];
Chris@0: }
Chris@0: else {
Chris@0: // Let client delete the BigPipe no-JS cookie.
Chris@0: $page['#attached']['html_head'][] = [
Chris@0: [
Chris@0: '#tag' => 'script',
Chris@0: '#value' => 'document.cookie = "' . BigPipeStrategy::NOJS_COOKIE . '=1; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"',
Chris@0: ],
Chris@0: 'big_pipe_detect_js',
Chris@0: ];
Chris@0: }
Chris@0: }
Chris@0: }