Exclude files from Load JavaScript Deferred

In some cases, the option Load JavaScript deferred  may conflict with a specific file.

If this option causes any problems, you may need to exclude a file from the process. 

Exclude files and domains

You can use the field in the plugin settings to exclude files:

 Exclusions may be done by using any of the following:

  • Full file URLs (with query strings removed)
  • Keywords from the file URL
  • Wildcards

Heads up!

Certain patterns of exclusions cannot be handled and are automatically removed.

If you add them, you should see a notice with the "WP Rocket: The following patterns are invalid and have been removed" message.

Please see more in our Invalid patterns of exclusions article.

Exclude inline scripts

You can use the rocket_defer_inline_exclusions filter to exclude specific inline scripts from being deferred, like this:

add_filter( 'rocket_defer_inline_exclusions', function( $inline_exclusions_list ) {
	$inline_exclusions_list[] = 'key_from_target_script';
	return $inline_exclusions_list;
} );

You'd need to replace key_from_target_script with a string of your real inline script.

You can add the above script as shown in the Add Code Snippets guide.

Note: if any jQuery library is excluded, WP Rocket won't defer inline JavaScript.


Exclude an externally hosted file

<script src="//maps.googleapis.com/maps/api/js?key=AIzaSyBusRuOn8uzsREWbwi-KCU4puf0me2aj3A&libraries=places" type="text/javascript"> </script>

You could simply use the domain:


This applies to external files that weren't minified by WP Rocket, and thus, kept their original external domain name.

Exclude a single file

To exclude this file:


Use the following:


Exclude a group of files

To exclude all files from a specific plugin folder, you could use a wildcard:


Use the following:


Exclude a minified file

To exclude a file which is also minified, the exclusion has to be based on the minified file URL. So choose a part of the URL (excluding the domain) which is unchanged by minification.

To exclude this file:

Use the following:


Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.