Production-ready scripts and configurations for achieving 90+ PageSpeed scores on WordPress sites.
wordpress-speed-optimization/
├── optimizations/
│ ├── remove-bloatware.php # Strip unnecessary WP scripts & styles
│ ├── critical-css-loader.php # Inline critical CSS, defer the rest
│ ├── image-optimization.php # WebP, lazy loading, CLS prevention
│ └── database-cleanup.php # Revisions, transients, table optimization
└── configs/
├── wp-rocket-optimal.json # Recommended WP Rocket settings
└── .htaccess-speed # Apache caching, gzip, browser caching
Removes every unnecessary WordPress default asset that most sites don't need:
- wp-emoji (saves ~15 KB + 1 DNS lookup)
- wp-embed (saves ~7 KB)
- jQuery Migrate (saves ~10 KB)
- Dashicons on the frontend (saves ~30 KB)
- Gutenberg block CSS (saves ~70 KB when not using the block editor)
- WordPress version exposure (security hardening)
- XML-RPC (attack surface reduction)
Eliminates render-blocking CSS using a two-phase loading strategy:
- Inlines critical above-the-fold CSS directly in
<head> - Defers all non-critical stylesheets via
media="print"+onloadswap - Adds
<link rel="preload">hints for fonts and key resources
Addresses the most common Core Web Vitals image failures:
- WebP delivery with PNG/JPEG fallback via
<picture>elements - Native lazy loading (
loading="lazy") on all non-LCP images - Explicit
widthandheightattributes to eliminate CLS - Optimized
srcsetandsizesoutput for responsive images
Keeps the database lean for faster queries:
- Removes post revisions (configurable retention count)
- Purges auto-drafts and orphaned metadata
- Cleans expired and orphaned transients
- Runs
OPTIMIZE TABLEon core WP tables
Battle-tested WP Rocket configuration covering:
- File minification & concatenation settings
- LazyLoad, preloading, and prefetch rules
- Database and CDN integration settings
Apache performance rules:
- Far-future
Expiresheaders (1 year for static assets) - Gzip / Deflate compression for all text-based assets
Cache-Controlheaders withimmutablefor versioned assets- ETags configuration
Copy the contents of any file in optimizations/ into your theme's functions.php,
or — better — into a must-use plugin:
wp-content/mu-plugins/speed-optimizations.php
Example mu-plugin wrapper:
<?php
/**
* Plugin Name: Speed Optimizations
* Description: Production speed tweaks — loaded before all other plugins.
*/
require_once __DIR__ . '/speed/remove-bloatware.php';
require_once __DIR__ . '/speed/critical-css-loader.php';
require_once __DIR__ . '/speed/image-optimization.php';Merge the rules from configs/.htaccess-speed into your existing .htaccess
above the # BEGIN WordPress block.
Import configs/wp-rocket-optimal.json via:
WP Rocket → Tools → Import Settings
| Metric | Before | After |
|---|---|---|
| PageSpeed Mobile | 45–60 | 90–98 |
| PageSpeed Desktop | 70–80 | 95–100 |
| LCP | 4–6 s | 1.2–2.0 s |
| TBT | 300–600 ms | < 100 ms |
| CLS | 0.15–0.30 | < 0.05 |
| Page Weight | 3–6 MB | 0.8–1.5 MB |
Results measured on a WooCommerce shop (shared hosting, no CDN). Actual results vary by theme, plugins, and hosting environment.
| Component | Version |
|---|---|
| PHP | 7.4, 8.0, 8.1, 8.2, 8.3 |
| WordPress | 5.8 – 6.x |
| WP Rocket | 3.x – 3.15.x |
| Apache | 2.4+ |
| MySQL / MariaDB | 5.7+ / 10.3+ |
These optimizations are theme-agnostic and work with: GeneratePress, Astra, Kadence, Divi, Elementor sites, WooCommerce, and plain WordPress installs.
- Always test on staging first. Some bloatware removals break poorly coded plugins.
- The critical CSS loader requires you to generate and maintain your own critical CSS string per template.
- XML-RPC disabling will break the WordPress mobile app and some backup plugins that rely on it — check before enabling.
- Database cleanup is destructive. Revisions and auto-drafts cannot be recovered after deletion.
MIT — use freely in client projects, agencies, and products.