README.md | 5 +-- big_pipe.module | 71 +++++++++++------------------ big_pipe.routing.yml | 9 ++++ big_pipe.services.yml | 2 +- src/Controller/BigPipeController.php | 62 +++++++++++++++++++++++++ src/Render/Placeholder/BigPipeStrategy.php | 72 +++++++++++++++++++++++------- 6 files changed, 158 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index b200b74..83fdb58 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,6 @@ Install like any other Drupal module. -Note: None of the existing sessions will be able to use BigPipe. Log out and log - in to benefit. To fix that, see https://www.drupal.org/node/2603046. - # Recommendations @@ -49,6 +46,8 @@ vcl_fetch { } ``` +Note that the `big_pipe_nojs` cookie does *not* break caching. Varnish should let that cookie pass through. + ## Other (reverse) proxies diff --git a/big_pipe.module b/big_pipe.module index f2615e6..516b29b 100644 --- a/big_pipe.module +++ b/big_pipe.module @@ -2,55 +2,38 @@ /** * @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(). + * Adds BigPipe no-JS detection. */ -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'; -} +use Drupal\big_pipe\Render\Placeholder\BigPipeStrategy; +use Drupal\Core\Url; /** - * 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