Why Performance Matters
- User Experience: 53% of users abandon a page if it takes more than 3 seconds to load.
- SEO Ranking: Google uses page speed as a ranking factor.
- Conversion Rate: Every 1-second improvement boosts conversion rates by 7%.
Performance Diagnostics
Testing Tools
| Tool | Purpose | Website |
|---|---|---|
| PageSpeed Insights | Official Google testing tool | 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 < 200 ms
- LCP: Largest Contentful Paint < 2.5 s
- FID: First Input Delay < 100 ms
- CLS: Cumulative Layout Shift < 0.1
Server Optimization
Choosing the Right Hosting
| Type | Suitable For | Recommended Providers |
|---|---|---|
| Shared Hosting | Small blogs | SiteGround |
| VPS | Medium-sized websites | Vultr, DigitalOcean |
| Managed Hosting | High-traffic sites | 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 Strategies
Page Caching
Convert dynamic pages into static HTML:
- WP Rocket (paid, best-in-class)
- W3 Total Cache (free, feature-rich)
- LiteSpeed Cache (for LiteSpeed servers)
Object Caching
Cache database query results:
// wp-config.php
define("WP_CACHE", true);
Redis is strongly recommended:
# 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 with WebP support
- Imagify: Works well alongside WP Rocket
- Smush: Free version is sufficient for most use cases
Use WebP Format
WebP files are 25–35% smaller than JPEGs:
// Most optimization plugins support automatic conversion
Lazy Loading
// Native in WordPress 5.5+
// Or enhanced via plugins
Database Optimization
Clean Up Redundant Data
-- Delete post 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 Entries
-- Check size of autoloaded options
SELECT SUM(LENGTH(option_value)) as autoload_size
FROM wp_options WHERE autoload = "yes";
-- Should be under 1 MB
Recommended Plugins
- WP-Optimize
- Advanced Database Cleaner
Frontend Optimization
Reduce HTTP Requests
- Combine CSS/JS files
- Use CSS sprites
- Inline critical CSS
Defer JavaScript Loading
<script src="script.js" defer></script>
Remove Unnecessary Resources
// Disable emoji script
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 CDNs
- Cloudflare (Free tier is sufficient for many use cases)
- BunnyCDN (Excellent value for money)
- KeyCDN
Domestic CDNs (China)
- Alibaba Cloud CDN
- Tencent Cloud CDN
- UpYun
- Qiniu
Configuration Best Practices
- Serve static assets from your CDN domain.
- Set appropriate cache expiration times.
- 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
- Using PHP 8.x
- Page caching enabled
- Object caching enabled (e.g., Redis)
- Images compressed and served in WebP format
- Lazy loading enabled
- CDN configured and active
- Database optimized
- Unused plugins removed
- Gzip compression enabled
- Critical CSS inlined
For performance issues, tag @speed experts for diagnostic assistance!