Performance: Custom meta boxes
MEDIUM IMPACT
Custom meta boxes affect the admin page load speed and responsiveness when editing posts or custom post types.
<?php add_action('add_meta_boxes', function() { add_meta_box('light_meta', 'Light Meta Box', function() { echo '<div id="meta-box-content">Loading...</div>'; }, 'post'); }); add_action('admin_footer-post.php', function() { ?> <script> fetch('/wp-json/custom/v1/meta-data') .then(res => res.json()) .then(data => { const container = document.getElementById('meta-box-content'); container.innerHTML = data.items.map(item => `<div>${item.title}</div>`).join(''); }); </script> <?php }); ?>
<?php add_action('add_meta_boxes', function() { add_meta_box('heavy_meta', 'Heavy Meta Box', function() { // Complex queries and large HTML output $data = get_posts(['numberposts' => 1000]); echo '<ul>'; foreach ($data as $post) { echo '<li>' . esc_html($post->post_title) . '</li>'; } echo '</ul>'; }, 'post'); }); ?>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous heavy meta box | Inserts 1000+ nodes at once | Triggers multiple reflows | High paint cost due to large DOM | [X] Bad |
| Asynchronous lightweight meta box | Inserts small DOM initially, loads more later | Single reflow on initial load | Lower paint cost with incremental updates | [OK] Good |