Make WordPress Core


Ignore:
Timestamp:
09/12/2023 12:04:15 AM (9 months ago)
Author:
westonruter
Message:

Bundled Themes: Use defer loading strategy for theme scripts.

  • Add defer loading strategy for all frontend end-user theme scripts (excluding Customizer preview).
  • Move scripts to the head which relate to the initial page viewport to ensure they start loading earlier and execute sooner while still not blocking rendering.
  • Update Twenty Twenty's script loader (TwentyTwenty_Script_Loader) to support core's built-in script loading strategies (#12009), while also retaining backwards-compatibility for child themes that may set async and defer script data.
  • Update the main script loading strategy in Twenty Twenty from async to defer for better performance on repeat page views, since when an async script is cached it will block rendering.

Props westonruter, flixos90, sabernhardt.
Fixes #59316.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwelve/functions.php

    r56526 r56556  
    189189
    190190    // Adds JavaScript for handling the navigation menu hide-and-show behavior.
    191     wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20141205', array( 'in_footer' => true ) );
     191    wp_enqueue_script(
     192        'twentytwelve-navigation',
     193        get_template_directory_uri() . '/js/navigation.js',
     194        array( 'jquery' ),
     195        '20141205',
     196        array(
     197            'in_footer' => false, // Because involves header.
     198            'strategy'  => 'defer',
     199        )
     200    );
    192201
    193202    $font_url = twentytwelve_get_font_url();
Note: See TracChangeset for help on using the changeset viewer.