XWP Critical Path WP Registry grade A. No security issues foundWP RegistryNo security issues foundOpen the reportA
Site-specific LCP-focused performance optimizations
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/xwp/xwp-critical-path/archive/refs/heads/main.zipA comprehensive WordPress performance optimization plugin focused on improving Largest Contentful Paint (LCP) and overall site performance through careful asset management and loading strategies.
Features
-
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
- Automatic cache invalidation on configuration changes
- Request-level caching to minimize database queries
- Smart cache clearing on plugin/theme changes
Installation
- Upload the
xwp-critical-pathfolder to/wp-content/plugins/ - Activate the plugin through the 'Plugins' menu in WordPress
- Configure settings under Settings > Performance Custom
Using Composer
To install the plugin via Composer, follow these steps:
-
Add the Repository:
-
Open your project's
composer.jsonfile. -
Add the following under the
repositoriessection:"repositories": [ { "type": "vcs", "url": "https://github.com/xwp/xwp-critical-path" } ]
-
-
Require the Plugin:
-
Run the following command in your terminal:
composer require xwp/xwp-critical-path
-
-
Activate the Plugin:
- Once installed, activate the plugin through the 'Plugins' menu in WordPress.
Configuration
Dequeue Stylesheets
Remove unnecessary stylesheets from loading:
- Enable the feature via checkbox
- Enter stylesheet handles (one per line) to remove
- Example:
unnecessary-plugin-style
Dequeue Scripts
Remove unused JavaScript files:
- Enable the feature
- List script handles to remove
- Example:
jquery-migrate(if not needed)
Globally Defer Stylesheets
Defer all stylesheets except critical ones:
- Enable stylesheet deferral
- List handles that should remain render-blocking (critical CSS)
- Example:
twenty-twenty-one-stylefor main theme styles
Globally Defer Scripts
Use modern loading strategies for JavaScript:
- Enable script deferral
- List handles that must remain blocking
- Scripts not listed will automatically use defer loading
Load Gutenberg CSS Inline
Optimize block editor styles:
- Simple checkbox to enable/disable
- Automatically loads block CSS only when blocks are present
Preload Assets
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:
Architecture
File Structure
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
Core Components
- 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
Performance Optimizations
- Request-Level Caching: Global variables prevent redundant processing
Hooks and Actions
Actions Used
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
Cache Management Hooks
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
Developer API
Accessing Plugin Settings
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
}
Parsing Configuration
use function XWP\Performance\Includes\AdminSettings\parse_textarea_lines;
// Convert textarea input to array
$handles = parse_textarea_lines( $settings['dequeue_scripts_handles'] );
Security
- 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
Performance Impact
Benefits
- Reduced render-blocking resources
- Improved LCP (Largest Contentful Paint)
- Optimized Critical Rendering Path
Requirements
- WordPress 6.3 or higher
- PHP 8.0 or higher
Best Practices
Critical CSS
- Identify above-the-fold styles
- Keep these as render-blocking in settings
- Defer everything else
Font Loading
- Host fonts locally when possible
- Preload the specific custom font files used by the title or body text
Script Deferral
- Keep user-critical scripts blocking
- Defer analytics and non-critical functionality
- Test thoroughly after changes
Troubleshooting
Styles Not Loading
- Check if critical styles are in the render-blocking list
- Verify handle names match exactly
- Clear browser cache after changes
JavaScript Errors
- 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
License
GPLv2 or later
Support
For issues, feature requests, or contributions, please contact XWP or use the plugin's support channels.
Changelog
1.0.0
- Initial release with six optimization modules
- Admin interface for configuration
- WordPress VIP coding standards compliance
- Comprehensive input sanitization
- Performance-focused architecture
1.0.1
- Remove transient caching system
- Add support for internationalization
Releases
2 releases.
These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.