Make WordPress Core


Ignore:
Timestamp:
10/21/2025 05:59:38 AM (12 months ago)
Author:
westonruter
Message:

Script Loader: Load block styles on demand in classic themes via the template enhancement output buffer.

  • This applies in classic themes when a site has not opted out of the template enhancement buffer by filtering wp_should_output_buffer_template_for_enhancement off.
  • Both should_load_separate_core_block_assets and should_load_block_assets_on_demand are filtered on, as otherwise they are only enabled by default in block themes.
  • Any style enqueued after wp_head and printed via print_late_styles() will get hoisted up to be inserted right after the wp-block-library inline style in the HEAD.
  • The result is a >10% benchmarked improvement in LCP for core classic themes due to a ~100KB reduction in the amount of CSS unconditionally being served with every page load.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/10288

Follow-up to [60936].

Props sjapaget, westonruter, peterwilsoncc, dmsnell, mindctrl.
See #43258.
Fixes #64099.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/wpEnqueueStoredStyles.php

    r55567 r61008  
    1111 */
    1212class Tests_Themes_WpEnqueueStoredStyles extends WP_Theme_UnitTestCase {
     13        /**
     14         * @var WP_Scripts|null
     15         */
     16        protected $original_wp_scripts;
     17
     18        /**
     19         * @var WP_Styles|null
     20         */
     21        protected $original_wp_styles;
     22
     23        public function set_up() {
     24                parent::set_up();
     25
     26                global $wp_scripts, $wp_styles;
     27                $this->original_wp_scripts = $wp_scripts;
     28                $this->original_wp_styles  = $wp_styles;
     29                $wp_scripts                = null;
     30                $wp_styles                 = null;
     31                wp_scripts();
     32                wp_styles();
     33        }
     34
     35        public function tear_down() {
     36                global $wp_scripts, $wp_styles;
     37                $wp_scripts = $this->original_wp_scripts;
     38                $wp_styles  = $this->original_wp_styles;
     39
     40                parent::tear_down();
     41        }
    1342
    1443        /**
    … …  
    1645         *
    1746         * @ticket 56467
     47         *
     48         * @covers ::wp_style_engine_get_stylesheet_from_css_rules
     49         * @covers ::wp_enqueue_stored_styles
    1850         */
    1951        public function test_should_enqueue_stored_styles() {
Note: See TracChangeset for help on using the changeset viewer.