Performance: Request and response handling
HIGH IMPACT
This affects how quickly the server processes user requests and sends back responses, impacting page load speed and interactivity.
<?php // In functions.php add_action('init', function() { global $wpdb; if (isset($_GET['action']) && $_GET['action'] === 'load_data') { $cache_key = 'load_data_cache'; $data = get_transient($cache_key); if (!$data) { $data = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_status = 'publish'"); set_transient($cache_key, $data, 3600); // Cache for 1 hour } echo json_encode($data); exit; } });
<?php // In functions.php add_action('init', function() { global $wpdb; if (isset($_GET['action']) && $_GET['action'] === 'load_data') { // Heavy database query without caching $data = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_status = 'publish'"); echo json_encode($data); exit; } });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy uncached DB query on every request | N/A (server-side) | N/A | Delays initial paint | [X] Bad |
| Cached DB query with transients | N/A (server-side) | N/A | Faster initial paint | [OK] Good |