Make WordPress Core


Ignore:
Timestamp:
09/25/2015 09:01:46 PM (10 years ago)
Author:
westonruter
Message:

Customizer: Defer embedding widget controls to improve DOM performance and initial load time.

The Menu Customizer feature includes a performance technique whereby the controls for nav menu items are only embedded into the DOM once the containing menu section is expanded. This commit implements the same DOM deferral for widgets but goes a step further than just embedding the controls once the widget area's Customizer section is expanded: it also defers the embedding of the widget control's form until the widget is expanded, at which point the widget-added event also fires to allow any additional widget initialization to be done. The deferred DOM embedding can speed up initial load time by 10x or more. This DOM deferral also yields a reduction in overall memory usage in the browser process.

Includes changes to wp_widget_control() to facilitate separating out the widget form from the surrounding accordion container; also includes unit tests for this previously-untested function. Also included are initial QUnit tests (finally) for widgets in the Customizer.

Fixes #33901.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-control.php

    r33734 r34563  
    14881488    public $is_wide = false;
    14891489
     1490    /**
     1491     * Gather control params for exporting to JavaScript.
     1492     *
     1493     * @global array $wp_registered_widgets
     1494     */
    14901495    public function to_json() {
     1496        global $wp_registered_widgets;
     1497
    14911498        parent::to_json();
    14921499        $exported_properties = array( 'widget_id', 'widget_id_base', 'sidebar_id', 'width', 'height', 'is_wide' );
     
    14941501            $this->json[ $key ] = $this->$key;
    14951502        }
    1496     }
    1497 
    1498     /**
    1499      *
    1500      * @global array $wp_registered_widgets
    1501      */
    1502     public function render_content() {
    1503         global $wp_registered_widgets;
     1503
     1504        // Get the widget_control and widget_content.
    15041505        require_once ABSPATH . '/wp-admin/includes/widgets.php';
    15051506
     
    15151516
    15161517        $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
    1517         echo $this->manager->widgets->get_widget_control( $args );
    1518     }
     1518        $widget_control_parts = $this->manager->widgets->get_widget_control_parts( $args );
     1519
     1520        $this->json['widget_control'] = $widget_control_parts['control'];
     1521        $this->json['widget_content'] = $widget_control_parts['content'];
     1522    }
     1523
     1524    /**
     1525     * Override render_content to be no-op since content is exported via to_json for deferred embedding.
     1526     */
     1527    public function render_content() {}
    15191528
    15201529    /**
Note: See TracChangeset for help on using the changeset viewer.