You are here

public function InitSubscriber::deferJs in Advanced CSS/JS Aggregation 8.3

Same name and namespace in other branches
  1. 8.4 advagg_mod/src/EventSubscriber/InitSubscriber.php \Drupal\advagg_mod\EventSubscriber\InitSubscriber::deferJs()

Apply defer JS changes.

Parameters

\Symfony\Component\HttpKernel\Event\FilterResponseEvent $response: The response event object.

File

advagg_mod/src/EventSubscriber/InitSubscriber.php, line 209

Class

InitSubscriber
Perform initialization tasks for advagg_mod.

Namespace

Drupal\advagg_mod\EventSubscriber

Code

public function deferJs(FilterResponseEvent $response) {

  // Skip if not enabled.
  if (!$this->config
    ->get('js_defer')) {
    return;
  }
  $response = $response
    ->getResponse();

  // Only process Html Responses.
  if (!$response instanceof HtmlResponse) {
    return;
  }
  $content = $this->jsDeferer
    ->defer($response
    ->getContent());
  $response
    ->setContent($content);
}