Verified Commit 784effb3 authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #734080 by catch, pwolanin, nod_, sun, owen barton, ksenzee: Set...

Issue #734080 by catch, pwolanin, nod_, sun, owen barton, ksenzee: Set preprocess: false for jquery.min.js to reduce duplication between asset aggregates
parent 395ba5de
Loading
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -756,7 +756,12 @@ jquery:
    url: https://raw.githubusercontent.com/jquery/jquery/4.0.0-beta.2/LICENSE.txt
    gpl-compatible: true
  js:
    assets/vendor/jquery/jquery.min.js: { minified: true, weight: -20 }
    # jquery.min.js is explicitly set to preprocess: false to prevent its
    # inclusion in JavaScript aggregates. This prevents it being duplicated
    # across different aggregates which can include different combinations of
    # libraries that depend on jQuery, so that it is only downloaded once per
    # browser instead of potentially multiple times from different pages.
    assets/vendor/jquery/jquery.min.js: { preprocess: false, minified: true, weight: -20 }

internal.jquery.form:
  # Internal library. Do not depend on it outside core nor add new core usage.
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ public function testLogin(): void {
      'CacheDeleteCount' => 0,
      'CacheTagInvalidationCount' => 0,
      'CacheTagLookupQueryCount' => 20,
      'ScriptCount' => 2,
      'ScriptCount' => 3,
      'ScriptBytes' => 215500,
      'StylesheetCount' => 1,
      'StylesheetBytes' => 46300,
+24 −3
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ public function testFrontAndRecipesPages(): void {
  }

  /**
   * Checks the asset requests made when the front and recipe pages are visited.
   * Checks the front and recipe page asset requests as an authenticated user.
   */
  public function testFrontAndRecipesPagesAuthenticated(): void {
    $user = $this->createUser();
@@ -47,14 +47,35 @@ public function testFrontAndRecipesPagesAuthenticated(): void {
    }, 'umamiFrontAndRecipePagesAuthenticated');

    $expected = [
      'ScriptCount' => 2,
      'ScriptBytes' => 249700,
      'ScriptCount' => 3,
      'ScriptBytes' => 170500,
      'StylesheetCount' => 6,
    ];
    $this->assertMetrics($expected, $performance_data);

  }

  /**
   * Checks the front and recipe page asset requests as an editor.
   */
  public function testFrontAndRecipesPagesEditor(): void {
    $user = $this->createUser();
    $user->addRole('editor');
    $user->save();
    $this->drupalLogin($user);
    sleep(2);
    $performance_data = $this->collectPerformanceData(function () {
      $this->doRequests();
    }, 'umamiFrontAndRecipePagesEditor');
    $expected = [
      'ScriptCount' => 5,
      'ScriptBytes' => 338200,
      'StylesheetCount' => 6,
      'StylesheetBytes' => 308500,
    ];
    $this->assertMetrics($expected, $performance_data);
  }

  /**
   * Performs a common set of requests so the above test methods stay in sync.
   */
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ public function testFrontPageAuthenticatedWarmCache(): void {
      'CacheDeleteCount' => 0,
      'CacheTagInvalidationCount' => 0,
      'CacheTagLookupQueryCount' => 2,
      'ScriptCount' => 1,
      'ScriptCount' => 2,
      'ScriptBytes' => 123850,
      'StylesheetCount' => 2,
      'StylesheetBytes' => 42500,
+3 −2
Original line number Diff line number Diff line
@@ -186,9 +186,10 @@ public function testAggregation(): void {
    [$header_js, $footer_js] = $this->assetResolver->getJsAssets($assets, TRUE, \Drupal::languageManager()->getCurrentLanguage());
    $this->assertEquals([], \Drupal::service('asset.js.collection_renderer')->render($header_js), 'There are 0 JavaScript assets in the header.');
    $rendered_footer_js = \Drupal::service('asset.js.collection_renderer')->render($footer_js);
    $this->assertCount(2, $rendered_footer_js, 'There are 2 JavaScript assets in the footer.');
    $this->assertCount(3, $rendered_footer_js, 'There are 3 JavaScript assets in the footer.');
    $this->assertEquals('drupal-settings-json', $rendered_footer_js[0]['#attributes']['data-drupal-selector'], 'The first of the two JavaScript assets in the footer has drupal settings.');
    $this->assertStringStartsWith(base_path(), $rendered_footer_js[1]['#attributes']['src'], 'The second of the two JavaScript assets in the footer has the sole aggregated JavaScript asset.');
    $this->assertStringContainsString('jquery.min.js', $rendered_footer_js[1]['#attributes']['src'], 'The second of the two JavaScript assets in the footer is jquery.min.js.');
    $this->assertStringStartsWith(base_path(), $rendered_footer_js[2]['#attributes']['src'], 'The third of the two JavaScript assets in the footer has the sole aggregated JavaScript asset.');
  }

  /**