wpcf7_is_ajax_call: Improve Contact Form 7 AJAX load time in WordPress

If you use the Contact Form 7 forms plugin in WordPress and, like me, you keep checking load times, it is likely that you have noticed the slowness of the wpcf7_is_ajax_call component. The reason is an incompatibility between both systems that we can solve by adding the following lines in the functions.php of your template, according to a Stackoverflow post:

// Hack Contact Form 7 to avoid unwanted ajax calls
// see http://stackoverflow.com/questions/19632244/is-w3-total-cache-compatible-with-contact-form-7
add_action('wpcf7_enqueue_scripts', 'hack_cf7');
function hack_cf7() {
$_wpcf7 = array(
'loaderUrl' => wpcf7_ajax_loader(),
'sending' => __( 'Sending ...', 'contact-form-7' )
);
wp_localize_script( 'contact-form-7', '_wpcf7', $_wpcf7 );
}

In my case I have achieved an average reduction of 900 ms with this patch, which in average loading times of 2 to 2.5 seconds is a real outrage

Scroll to Top