JavaScript (JS) issue between Autoptimize and Contact Form 7 plugins

When using Autoptimize plugin, there is a possible issue if you are also using Contact Forms 7 plugin. The combined JSfile will be broken. If you inspect (F12) your site, it will show an error like this

The error message is “_wpcf7 is not defined“.

js-issue-autoptimize-contactform7-1

It’s because the JS file of Contact Form 7 is not quite valid, so Autoptimize fails to compress correctly. As a result, the whole page can crash because of the broken JS. To fix this, you need to exclude Contact Form 7’s JS file from Autoptimize list.

Please go to Settings > Autoptimize > JavaScript Option > add “scripts.js” to the list in “Exclude scripts from Autoptimize” text box (make sure you click on “Show Advanced Settings” button to be able to see this text box).

exclude-scripts-form-autoptimize