Exclude files from Load JavaScript Deferred
In this Article
In some cases, the option Load JavaScript deferred (in File Optimization → JavaScript Files) may conflict with a specific file.
If this option causes any problems, you may need to exclude a file from the process.
WP Rocket 3.8+
From WP Rocket 3.8 there is a 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
Examples
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:
maps.googleapis.com
Exclude a single file
To exclude this file:
https://example.org/wp-content/plugins/elementor-pro/assets/js/frontend.min.js?ver=3.0.5
Use the following:
https://example.org/wp-content/plugins/elementor-pro/assets/js/frontend.min.js
Exclude a group of files
To exclude all files from a specific plugin folder, you could use a wildcard:
https://www.example.org/wp-content/plugins/my-plugin/assets/js/um-crop.min.js?ver=2.1.12
Use the following:
/wp-content/plugins/my-plugin/assets/js/(.*).js
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 which is unchanged by minification.
To exclude this file:
https://www.example.org/wp-content/cache/min/1/wp-content/plugins/plugin-name/assets/js/pickadate/picker.time-f9a2f2b5fb728f25892f2f41b6f8a4b9.js
Use the following:
plugin-name/assets/js/pickadate/picker.time
WP Rocket versions prior to 3.8
Exclusions are made by downloading, installing, and editing the following small helper plugin.
📥 Download (.zip): WP Rocket | Exclude Files from Defer JS
Developers: You can find the code for this plugin on GitHub.
Heads up! You must edit the helper plugin before use!
Remove the sample value of /wp-includes/js/jquery/jquery.masonry.min.js
and insert the script path you wish to exclude. In order to exclude multiple files, copy the entire line, paste it after the first one, and edit the file path accordingly.
Tips to make this work
Files hosted on your own domain
Remove query string
Remove any query string following the .js
extension. For example, to exclude:
https://example.com/wp-content/themes/neutro/js/responsive-menu.js?ver=46e6ce
use:
$excluded_files[] = '/wp-content/themes/neutro/js/responsive-menu.js';
Exclude files from Minify/Combine
If Minify JS or Combine JS is also active, you must exclude the files from that option as well.
Files hosted on external domains
From WP Rocket 3.1.3, you may exclude external JS files (i.e. those not hosted on your domain) using:
- Only the domain
- Any part of the URL
- Wildcards
For example, to exclude this URL:
https://ws.sharethis.com/button/st_insights.js?publisher=123-abc-456&product=simpleshare
any of the following will work:
$excluded_files[] = '/button/st_insights.js';
$excluded_files[] = 'ws.sharethis.com';
$excluded_files[] = 'https://ws.sharethis.com/button/(.*).js';