Skip to content

ehonep/wordpress-speed-optimization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

WordPress Speed Optimization Toolkit

Production-ready scripts and configurations for achieving 90+ PageSpeed scores on WordPress sites.

License: MIT PHP WordPress


What's Inside

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

optimizations/remove-bloatware.php

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)

optimizations/critical-css-loader.php

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" + onload swap
  • Adds <link rel="preload"> hints for fonts and key resources

optimizations/image-optimization.php

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 width and height attributes to eliminate CLS
  • Optimized srcset and sizes output for responsive images

optimizations/database-cleanup.php

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 TABLE on core WP tables

configs/wp-rocket-optimal.json

Battle-tested WP Rocket configuration covering:

  • File minification & concatenation settings
  • LazyLoad, preloading, and prefetch rules
  • Database and CDN integration settings

configs/.htaccess-speed

Apache performance rules:

  • Far-future Expires headers (1 year for static assets)
  • Gzip / Deflate compression for all text-based assets
  • Cache-Control headers with immutable for versioned assets
  • ETags configuration

Usage

Drop-in (functions.php)

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';

.htaccess

Merge the rules from configs/.htaccess-speed into your existing .htaccess above the # BEGIN WordPress block.

WP Rocket

Import configs/wp-rocket-optimal.json via: WP Rocket → Tools → Import Settings


Results

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.


Tech Compatibility

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.


Safety Notes

  • 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.

License

MIT — use freely in client projects, agencies, and products.

About

Production-ready scripts for achieving 90+ PageSpeed scores on WordPress sites

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages