Fix "Uncaught ReferenceError: captainform_preload_form_popup is not defined"


Are your CaptainForms not working, or are you seeing "Uncaught ReferenceError: captainform_preload_form_popup is not defined" in your website's console? This error can disrupt the functionality of your site's features, such as accordions or tabs that suddenly refuse to work. Fortunately, this issue is resolvable, most commonly associated with conflicts arising from script deferral in caching and optimization plugins like WP Rocket.

Resolve the "Uncaught ReferenceError: captainform_preload_form_popup" error by:

  1. Temporarily disabling WP Rocket to check if errors stop.
  2. If resolved, exclude 'captainform-form-popup.js' from WP Rocket's script deferral.
  3. Clear cache and verify if site features work without error.

Understanding the Error

The error indicates that the browser is attempting to call a function from the CaptainForm plugin before the function has been loaded and defined in the global scope. This scenario is common when JavaScript scripts are deferred in order to improve the loading times of web pages.

WP Rocket Configuration

If you are using WP Rocket, then to resolve the JavaScript error, you'll often need to adjust the settings of your caching plugin to ensure the necessary scripts are not deferred. Here are the steps to fine-tune WP Rocket:

Troubleshoot with WP Rocket Disabled:

Temporarily disable WP Rocket on your website. By doing so, you check if script deferral is the cause of the issue. If the error vanishes and the Captain Forms on your site start work correctly, you've found the culprit.

Exclude Scripts from Deferral:

Rather than keeping WP Rocket disabled (which could impact your site's performance), you can tell WP Rocket to exclude the CaptainForm script from being deferred. To do this, you'll need to:

  • Access WP Rocket's settings in your WordPress admin panel.
  • Navigate to the File Optimization tab.
  • Scroll to the JavaScript section where you have the option to defer JavaScript files.
  • Add the name of the JavaScript file – captainform-form-popup.js – to the exclusion list.

This exclusion ensures the script loads in the correct order, allowing the CaptainForm’s functions to define before any attempts to use them. Consult WP Rocket's documentation for detailed guidance: Exclude files from Load JavaScript Deferred.

Verify the Results:

After making these changes, clear your site’s cache and browser cache. Then verify that the site is functioning correctly with no errors in the console.

Script deferral is a powerful speed optimization, but occasionally, it may need tweaking to play nicely with all your plugins. By following these steps, you'll be able to enjoy both the speed advantages of WP Rocket and the full functionality of the CaptainForm plugin.


Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

We may earn a commission when you visit links on our website.