• Resolved Chris Whitford

    (@fcwhitford)


    By default, wpcf7 loads its scripts.js file in the footer, but jquery.js, which is a dependency, still gets loaded in the header. (WP still does this in 5.2.2.) The only way I’ve found to change this behaviour is to patch controller.php. Instead of using the ‘in_footer’ parameter of wp_enqueue_script(), I test wpcf7_load_js() and conditionally add wpcf_enqueue_scripts() to the ‘wp_head’ action instead of the ‘wp_enqueue_scripts’ action. wp_head comes too late for the script to be loaded in the header so it gets loaded in the footer, This seems to be the most reliable way to enqueue scripts in the footer, but it’s not very convenient as it means patching the plugin code. Could the developers look into this please?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Contact Form 7 doesn’t load the jquery.js. It’s WordPress core’s job, and loading it in the header is not a problem, it’s a correct behavior.

    Thread Starter Chris Whitford

    (@fcwhitford)

    Thanks for your reply.
    Current advice, to speed up page loading, is to load JS asynchronously or in the footer wherever possible. Loading jquery is triggered by the first script which depends on it. As noted, if the in_footer parameter in wp_enqueue_scripts() is true, it loads the script in the footer but loads dependencies as in the header (if called early enough). If some other script also depended on jquery and had to be in the header, that would cause jquery to be loaded. On my site there are no JS scripts explicitly loaded in the header so there is no benefit having jquery loaded early.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘jquery.js doesn’t load in the footer’ is closed to new replies.