0
0
Wordpressframework~8 mins

Request and response handling in Wordpress - Performance & Optimization

Choose your learning style9 modes available
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.
Handling user requests in WordPress to serve page content
Wordpress
<?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;
  }
});
Uses WordPress transient caching to avoid repeated heavy queries, reducing server processing time.
📈 Performance GainReduces server processing time by 80%, improving LCP and lowering CPU load
Handling user requests in WordPress to serve page content
Wordpress
<?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;
  }
});
This runs a heavy database query on every request without caching, causing slow response times and high server load.
📉 Performance CostBlocks rendering for 200+ ms on each request, increasing LCP and server CPU usage
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Heavy uncached DB query on every requestN/A (server-side)N/ADelays initial paint[X] Bad
Cached DB query with transientsN/A (server-side)N/AFaster initial paint[OK] Good
Rendering Pipeline
The request hits the server, WordPress processes PHP code including database queries, then generates HTML or JSON response sent to the browser. The browser parses and paints the content.
Server Processing
Network Transfer
Browser Parsing
Paint
⚠️ BottleneckServer Processing due to heavy or uncached database queries
Core Web Vital Affected
LCP
This affects how quickly the server processes user requests and sends back responses, impacting page load speed and interactivity.
Optimization Tips
1Cache expensive database queries to reduce server processing time.
2Avoid running heavy queries on every request without caching.
3Use DevTools Network panel to monitor server response times.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of caching database query results in WordPress request handling?
AMakes the browser do more work
BIncreases the number of database queries
CReduces server processing time and speeds up response
DAdds extra network requests
DevTools: Network
How to check: Open DevTools, go to Network tab, reload page, and check the Time column for server response time (TTFB).
What to look for: Look for long TTFB (Time To First Byte) indicating slow server response; shorter times mean better request handling.