WP Rocket is a great plugin to speed up your WordPress site. One of its features, named “Load JavaScript Deferred”, helps speed up your site by delaying the loading of JavaScript files until after the main content is displayed.
However, this can sometimes interfere with scripts that need to load right away.
If something on your site breaks after enabling “Load JavaScript Deferred”, you might need to exclude specific files or scripts from this optimization.
When Should You Use “Load JavaScript Deferred”?
This feature is most effective for speeding up the initial page render. It works best on content-heavy pages without interactive elements. Avoid using it or prepare to exclude scripts if your site depends on:
- Live chat widgets
- Interactive sliders
- Maps (like Google Maps)
- Form validation scripts
- Analytics or tracking tools
In these cases, you’ll likely need to manually exclude scripts that break functionality, here’s how to do that:
Exclude Files and Domains
To exclude a script file, go to WP Rocket → File Optimization → JavaScript Files, and look for the field called “Excluded JavaScript Files”.

You can exclude scripts using:
- The full URL of the script (remove any
?ver=
or extra parameters) - A keyword from the URL
- A wildcard to match a group of files
⚠️ If you enter an invalid pattern, WP Rocket will remove it and show a warning message: “WP Rocket: The following patterns are invalid and have been removed”.
More details are available in the invalid patterns article.
How to Identify Scripts to Exclude
If something breaks after enabling the feature, open your browser’s developer tools (F12
or Right Click → Inspect
) and check the Console tab for errors. Look for:
- Script 404 errors
- “Is not defined” JavaScript errors
- jQuery-related issues
Match those errors with script names or IDs in your site’s HTML source.
Exclude Inline Scripts
If the problem comes from inline JavaScript (scripts inside your HTML, not loaded from a file), you can use this WordPress filter in your theme’s functions.php
file or via a code snippets plugin:
add_filter( 'rocket_defer_inline_exclusions', function( $inline_exclusions_list ) {
if ( ! is_array( $inline_exclusions_list ) ) {
$inline_exclusions_list = array();
}
// Add your keyword here
$inline_exclusions_list[] = 'custom-chat-widget-inline-js';
return $inline_exclusions_list;
} );
In this example, we’re excluding a script with this ID:
<script id="custom-chat-widget-inline-js">
var chatOptions = { theme: "dark", autoOpen: false };
</script>
The keyword custom-chat-widget-inline-js
will match that specific inline script.
Important: If any jQuery file is excluded, WP Rocket will stop deferring all inline scripts for safety.
Examples
1. Exclude a live chat widget script
<script src="https://cdn.livechat.com/widget.js?account=12345"></script>
Use this in the exclusion field:
cdn.livechat.com
2. Exclude a specific theme file
To exclude this file:
https://yoursite.com/wp-content/themes/your-theme/js/animations.js?ver=1.2.0
Use:
/wp-content/themes/your-theme/js/animations.js
3. Exclude all JavaScript files from a custom plugin
Use this format to target all files in a specific folder:
/wp-content/plugins/custom-gallery/js/(.*).js
4. Exclude a minified script loaded from cache
To exclude this file:
https://yourdomain.com/wp-content/cache/min/1/wp-content/plugins/social-share/js/share.min-ab123c456.js
Use:
social-share/js/share.min
Always test your site after excluding any script. If something still doesn’t work, try a broader or more specific pattern based on the file name or location.
Best Practices for Managing Script Exclusions
To get the most out of “Load JavaScript Deferred” while keeping your site functional, follow these tips:
- Exclude as few scripts as possible, each one reduces the benefit of defer.
- Prefer keywords over full URLs to keep exclusions flexible across environments.
- Document your exclusions in a comment or internal doc for future updates.
- Combine this feature with other optimizations like Critical CSS and Lazy Loading.
Summary
WP Rocket’s “Load JavaScript Deferred” feature helps improve site speed by delaying JavaScript loading. But sometimes it may cause issues with specific scripts. In those cases, you can exclude certain files or inline scripts:
- Use the Excluded JavaScript Files field in WP Rocket → File Optimization.
- Exclude scripts by full URL (without
?ver=
), keyword, or wildcard pattern. - To exclude inline scripts, use the
rocket_defer_inline_exclusions
filter in your theme’sfunctions.php
file. - Examples in this guide include excluding live chat scripts, custom theme files, plugin folders, and cached minified scripts.
Always test your site after excluding scripts to make sure everything works as expected.