Aleš Sýkora / November 28, 2023 / 0 comments
WP Rocket + Toolset Exclude files from Defer JS
1 min read / WordPress / Share on: Twitter, LinkedIn, Facebook
Post summary: If you use WP Rocket + Toolset (especially Toolset forms) you should exclude deferring some scripts.
If you use WP Rocket + Toolset (especially Toolset forms) you should exclude deferring some scripts. If you use Forms than it is a must. Without excluding you get some errors in console, like this one:
The scripts are:
validation.js
codemirror.js
conditional.js
recaptcha-v2/api.js
For excluding you need small plugin from WP Rocket. You can found it here: https://docs.wp-rocket.me/article/976-exclude-files-from-defer-js
After downloading and installing this plugin, go to /wp-content/plugins/wp-rocket-static-exclude-defer-js and open wp-rocket-static-exclude-defer-js.php in code editor.
Now you must change the URL /wp-includes/js/jquery/jquery.masonry.min.js to URL of script you want to exclude from defer.
$excluded_files[] = '/wp-includes/js/jquery/jquery.masonry.min.js';
change to:
$excluded_files[] = '/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/toolset-forms/js/validation.js';
$excluded_files[] = '/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/visual-editor/res/js/codemirror/lib/codemirror.js';
$excluded_files[] = '/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/toolset-forms/js/conditional.js';
$excluded_files[] = '/wp-content/plugins/cred-frontend-editor/vendor/toolset/toolset-common/toolset-forms/js/recaptcha-v2/api.js';
Save the file, clear the cache and everything works fine again :-).
Fuel my passion for writing with a beer🍺
Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻