Keep Critical Scripts Out of WP Rocket's Delay JavaScript
Excludes scripts you list, such as a consent banner, chat widget or analytics loader, from WP Rocket's "Delay JavaScript execution" so they run right away.
Opens WPIDE on
Code
$wpide_keep = array( 'cookieyes', 'complianz', 'googletagmanager.com', 'jquery.min.js' ); // Patterns.
add_filter( 'rocket_delay_js_exclusions', function ( $exclusions ) use ( $wpide_keep ) {
return array_values( array_unique( array_merge( (array) $exclusions, $wpide_keep ) ) );
} );
Notes
Use part of the script's file name or a keyword from an inline script. Clear WP Rocket's cache after activating.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.