Performance: Admin menu pages
MEDIUM IMPACT
This affects the loading speed and responsiveness of WordPress admin dashboard pages, impacting how quickly menus and submenus appear and respond to user actions.
<?php add_action('admin_menu', function() { add_menu_page('Light Page', 'Light Page', 'manage_options', 'light-page', function() { echo '<div id="data-container">Loading data...</div>'; ?> <script> fetch(ajaxurl + '?action=load_data') .then(res => res.text()) .then(html => document.getElementById('data-container').innerHTML = html); </script> <?php }); }); add_action('wp_ajax_load_data', function() { global $wpdb; $results = $wpdb->get_results('SELECT * FROM wp_large_table LIMIT 50'); foreach ($results as $row) { echo esc_html($row->data) . '<br>'; } wp_die(); }); ?>
<?php add_action('admin_menu', function() { add_menu_page('Heavy Page', 'Heavy Page', 'manage_options', 'heavy-page', function() { global $wpdb; $results = $wpdb->get_results('SELECT * FROM wp_large_table'); foreach ($results as $row) { echo esc_html($row->data) . '<br>'; } }); }); ?>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous data load in menu page | Large DOM tree generated at once | Multiple reflows triggered | High paint cost due to many elements | [X] Bad |
| Asynchronous data loading with AJAX | Small initial DOM, incremental updates | Single reflow after data load | Lower paint cost with fewer elements initially | [OK] Good |