X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fbig_pipe%2Fbig_pipe.module;fp=web%2Fcore%2Fmodules%2Fbig_pipe%2Fbig_pipe.module;h=fa0518ad3d1fff9db8a44f25a089e1a04fb58f01;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/big_pipe/big_pipe.module b/web/core/modules/big_pipe/big_pipe.module new file mode 100644 index 000000000..fa0518ad3 --- /dev/null +++ b/web/core/modules/big_pipe/big_pipe.module @@ -0,0 +1,78 @@ +' . t('About') . ''; + $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']) . '

'; + $output .= '

' . t('Uses') . '

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