getAlreadyLoadedLibraries example

    // variation, first normalize the requested libraries to the minimal     // representative set before then expanding the list to include all     // dependencies.     // @see Drupal\FunctionalTests\Core\Asset\AssetOptimizationTestUmami     // @todo: https://www.drupal.org/project/drupal/issues/1945262     $libraries = $assets->getLibraries();
    if ($libraries) {
      $libraries = $this->libraryDependencyResolver->getMinimalRepresentativeSubset($libraries);
    }
    return array_diff(
      $this->libraryDependencyResolver->getLibrariesWithDependencies($libraries),
      $this->libraryDependencyResolver->getLibrariesWithDependencies($assets->getAlreadyLoadedLibraries())
    );
  }

  /** * {@inheritdoc} */
  public function getCssAssets(AttachedAssetsInterface $assets$optimize, LanguageInterface $language = NULL) {
    if (!isset($language)) {
      $language = $this->languageManager->getCurrentLanguage();
    }
    $theme_info = $this->themeManager->getActiveTheme();
    
// Create a new HtmlResponse. Ensure the CSS and (non-bottom) JS is sent       // before the HTML they're associated with.       // @see \Drupal\Core\Render\HtmlResponseSubscriber       // @see template_preprocess_html()       $js_bottom_placeholder = '<nojs-bigpipe-placeholder-scripts-bottom-placeholder token="' . Crypt::randomBytesBase64(55) . '">';

      $html_response = new HtmlResponse();
      $html_response->setContent([
        '#markup' => BigPipeMarkup::create($js_bottom_placeholder),
        '#attached' => [
          'drupalSettings' => $cumulative_assets->getSettings(),
          'library' => $cumulative_assets->getAlreadyLoadedLibraries(),
          'html_response_attachment_placeholders' => [
            'scripts_bottom' => $js_bottom_placeholder,
          ],
        ],
      ]);
      $html_response->getCacheableMetadata()->setCacheMaxAge(0);

      // Push a fake request with the asset libraries loaded so far and dispatch       // KernelEvents::RESPONSE event. This results in the attachments for the       // HTML response being processed by HtmlResponseAttachmentsProcessor and       // hence the HTML to load the bottom JavaScript can be rendered.
Home | Imprint | This part of the site doesn't use cookies.