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 ) {
  if ( ! is_array( $inline_exclusions_list ) ) {
    $inline_exclusions_list = array();

  // Duplicate this line if you need to exclude more
  $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.

Please note, key_from_target_script should be a unique word that is used only in the script you want to exclude, because if the same word is used in other scripts then all the scripts in which it is used will be excluded.

For example, in this script:

<script id='kl-identify-browser-js-extra'> var klUser = {"current_user_email":"","commenter_email":""}; </script>

kl-identify-browser-js-extra would be a good candidate.

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.