Complete Guide to WordPress Performance Optimization

Why is Performance Important?

  • User Experience: If a page takes more than 3 seconds to load, 53% of users will leave.
  • SEO Ranking: Google uses speed as a ranking factor.
  • Conversion Rate: Every 1-second improvement in speed can increase conversions by 7%.

Performance Diagnosis

Testing Tools

Tool Purpose Address
PageSpeed Insights Official Google Test pagespeed.web.dev
GTmetrix Detailed Waterfall Analysis gtmetrix.com
WebPageTest Multi-location Testing webpagetest.org
Query Monitor Database Query Analysis WordPress Plugin

Key Metrics

  • TTFB: Time to First Byte < 200ms
  • LCP: Largest Contentful Paint < 2.5s
  • FID: First Input Delay < 100ms
  • CLS: Cumulative Layout Shift < 0.1

Server Optimization

Choosing the Right Hosting

Type Suitable For Recommended
Shared Hosting Small Blogs SiteGround
VPS Medium-sized Websites Vultr, DigitalOcean
Managed Hosting High Traffic Cloudways, Kinsta

PHP Version

  • Use PHP 8.1 or 8.2.
  • PHP 8 is 10-20% faster than PHP 7.4.

Enable OPcache

; php.ini
opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=20000

Caching Strategy

Page Caching

Convert dynamic pages to static HTML:

  • WP Rocket (Paid, Best)
  • W3 Total Cache (Free, Full-featured)
  • LiteSpeed Cache (For LiteSpeed Servers)

Object Caching

Cache database query results:

// wp-config.php
define("WP_CACHE", true);

Recommend using Redis:

# Install Redis
apt install redis-server

# WordPress Plugin
Redis Object Cache

Browser Caching

# .htaccess
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>

Image Optimization

Compress Images

  • ShortPixel: Smart compression, supports WebP.
  • Imagify: Companion to WP Rocket.
  • Smush: Free version is sufficient.

Use WebP Format

WebP is 25-35% smaller than JPEG:

// Most optimization plugins support automatic conversion

Lazy Loading

// Native support in WordPress 5.5+
// Or use a plugin for enhanced features

Database Optimization

Clean Up Redundant Data

-- Delete revisions
DELETE FROM wp_posts WHERE post_type = "revision";

-- Clean up auto-drafts
DELETE FROM wp_posts WHERE post_status = "auto-draft";

-- Optimize tables
OPTIMIZE TABLE wp_posts, wp_postmeta, wp_options;

Optimize autoload

-- Check autoload data size
SELECT SUM(LENGTH(option_value)) as autoload_size
FROM wp_options WHERE autoload = "yes";

-- Should be less than 1MB

Recommended Plugins

  • WP-Optimize
  • Advanced Database Cleaner

Frontend Optimization

Reduce HTTP Requests

  • Merge CSS/JS files.
  • Use CSS Sprites.
  • Inline critical CSS.

Defer JavaScript Loading

<script src="script.js" defer></script>

Remove Unnecessary Resources

// Remove emoji scripts
remove_action("wp_head", "print_emoji_detection_script", 7);

// Remove jQuery Migrate
add_action("wp_default_scripts", function($scripts) {
    if (!is_admin()) {
        $scripts->remove("jquery");
        $scripts->add("jquery", false, array("jquery-core"), "3.6.0");
    }
});

CDN Acceleration

International CDN

  • Cloudflare (Free tier is sufficient)
  • BunnyCDN (Good value)
  • KeyCDN

China-specific CDN

  • Alibaba Cloud CDN
  • Tencent Cloud CDN
  • UPYun
  • Qiniu Cloud

Configuration Key Points

  1. Use a CDN domain for static resources.
  2. Set appropriate cache times.
  3. Enable Gzip/Brotli compression.

China-specific Optimizations

Replace Google Fonts

// functions.php
function remove_google_fonts() {
    wp_deregister_style("open-sans");
    wp_register_style("open-sans", false);
}
add_action("wp_enqueue_scripts", "remove_google_fonts");

Replace Gravatar

Use Cravatar or local avatars:

// Use WPCom mirror
add_filter("get_avatar_url", function($url) {
    return str_replace("gravatar.com", "cravatar.cn", $url);
});

Performance Checklist

  • Use PHP 8.x
  • Enable Page Caching
  • Enable Object Caching (Redis)
  • Images are compressed and use WebP
  • Enable Lazy Loading
  • Use a CDN
  • Database is optimized
  • Remove unused plugins
  • Enable Gzip compression
  • Inline Critical CSS

For performance issues, you can ask the @speed expert for help with diagnosis!