A comprehensive WordPress performance optimization plugin focused on improving Largest Contentful Paint (LCP) and overall site performance through careful asset management and loading strategies.
-
Asset Deferral & Optimization
- Globally defer non-critical JavaScript with configurable exceptions
- Defer non-critical stylesheets while preserving render-blocking critical CSS
- Smart detection of print stylesheets
- WordPress 6.3+ script loading strategies support
-
Asset Management
- Remove unused stylesheets from specific pages
- Remove unnecessary scripts to reduce payload
- Granular control over WordPress core and plugin assets
- Handle-based configuration for precise control
-
Resource Preloading
- Preload critical CSS files with automatic versioning
- Preload custom resources (fonts, images, etc.)
- Intelligent resource type detection
- Support for both absolute and relative URLs
-
Gutenberg Optimization
- Load block CSS inline only when blocks are used
- Reduces unused CSS on pages without specific blocks
- Automatic per-page optimization
-
Performance Features
- Transient caching for improved performance on high-traffic sites
- Automatic cache invalidation on configuration changes
- Request-level caching to minimize database queries
- Smart cache clearing on plugin/theme changes
- Upload the
xwp-critical-path
folder to/wp-content/plugins/
- Activate the plugin through the 'Plugins' menu in WordPress
- Configure settings under Settings > Performance Custom
Remove unnecessary stylesheets from loading:
- Enable the feature via checkbox
- Enter stylesheet handles (one per line) to remove
- Example:
unnecessary-plugin-style
Remove unused JavaScript files:
- Enable the feature
- List script handles to remove
- Example:
jquery-migrate
(if not needed)
Defer all stylesheets except critical ones:
- Enable stylesheet deferral
- List handles that should remain render-blocking (critical CSS)
- Example:
twenty-twenty-one-style
for main theme styles
Use modern loading strategies for JavaScript:
- Enable script deferral
- List handles that must remain blocking
- Scripts not listed will automatically use defer loading
Optimize block editor styles:
- Simple checkbox to enable/disable
- Automatically loads block CSS only when blocks are present
Accelerate loading of critical resources:
- Enable preloading
- CSS Handles: Enter registered stylesheet handles to preload
- Custom URLs: Add direct URLs for fonts and other resources
- Relative:
/wp-content/themes/your-theme/fonts/font.woff2
- Absolute:
https://example.com/critical.css
- Relative:
xwp-critical-path/
├── xwp-critical-path.php # Main plugin file with constants
├── includes/
│ ├── admin-settings.php # Settings page and admin interface
│ ├── defer-scripts.php # Script deferral logic
│ ├── defer-stylesheets.php # Stylesheet deferral logic
│ ├── dequeue-scripts.php # Script removal functionality
│ ├── dequeue-stylesheet.php # Stylesheet removal functionality
│ ├── load-gutenberg-css-inline.php # Block CSS optimization
│ └── preload-assets.php # Resource preloading
├── assets/
│ ├── css/
│ │ └── admin-settings.css # Admin interface styles
│ └── js/
│ └── admin-settings.js # Admin UI enhancements
└── README.md
- Admin Settings: Centralized configuration management with sanitization
- Defer Scripts: Modern script loading using WordPress 6.3+ strategies
- Defer Stylesheets: Non-blocking CSS with noscript fallbacks
- Dequeue Assets: Selective removal of unnecessary resources
- Preload Assets: Critical resource prioritization
- Gutenberg Optimization: Smart block CSS loading
- Transient Caching: 12-hour cache for processed handles
- Request-Level Caching: Global variables prevent redundant processing
- Smart Invalidation: Automatic cache clearing on:
- Settings updates
- Plugin activation/deactivation
- Theme switches
- WordPress updates
wp_enqueue_scripts
- Asset modifications (priorities 100, 999)wp_head
- Preload tag injection (priority 1)admin_menu
- Settings page registrationadmin_init
- Settings initializationstyle_loader_tag
- Stylesheet deferralshould_load_separate_core_block_assets
- Gutenberg optimization
activated_plugin
- Clear cache on plugin activationdeactivated_plugin
- Clear cache on plugin deactivationafter_switch_theme
- Clear cache on theme changeupgrader_process_complete
- Clear cache after updates
use function XWP\Performance\Includes\AdminSettings\get_settings;
// Get all settings
$settings = get_settings();
// Check if a feature is enabled
if ( ! empty( $settings['defer_scripts_enabled'] ) ) {
// Feature is active
}
use function XWP\Performance\Includes\AdminSettings\parse_textarea_lines;
// Convert textarea input to array
$handles = parse_textarea_lines( $settings['dequeue_scripts_handles'] );
use function XWP\Performance\Includes\AdminSettings\clear_performance_transients;
// Clear all performance-related caches
clear_performance_transients();
- Input Sanitization: All user inputs validated and sanitized
- Output Escaping: Proper escaping with
esc_attr()
,esc_url()
,esc_textarea()
- Nonce Verification: WordPress settings API handles nonces
- Capability Checks: Admin-only access via
manage_options
- Safe Regex Patterns: Validated handle names and URLs
- Reduced render-blocking resources
- Improved LCP (Largest Contentful Paint)
- Optimized Critical Rendering Path
- WordPress 6.3 or higher
- PHP 8.0 or higher
- Identify above-the-fold styles
- Keep these as render-blocking in settings
- Defer everything else
- Host fonts locally when possible
- Preload the specific custom font files used by the title or body text
- Keep user-critical scripts blocking
- Defer analytics and non-critical functionality
- Test thoroughly after changes
- Check if critical styles are in the render-blocking list
- Verify handle names match exactly
- Clear browser cache after changes
- Some scripts may need to remain blocking
- Check browser console for dependency issues, as for example inline scripts that have dependencies will require them to be added to the blocking script handles allow list.
- Add problematic scripts to blocking list
- Settings changes automatically clear cache
- Cache is also cleared when plugins/themes change
- Transients expire after 12 hours automatically
GPLv2 or later
For issues, feature requests, or contributions, please contact XWP or use the plugin's support channels.
- Initial release with six optimization modules
- Admin interface for configuration
- Transient caching system
- Smart cache invalidation
- WordPress VIP coding standards compliance
- Comprehensive input sanitization
- Performance-focused architecture