Deregistering Jquery doesnt account for enqueued dependencies cause double load
-
After reading the support ticket here https://www.ads-software.com/support/topic/multiple-copies-of-jquery-loading?replies=4, I found I was experiencing the same issue. I had narrowed the plugin down to specifically Bannerspace and Contact Form 7, and discovered the reason this is occuring, though I don’t know the solution.
It is true the theme deregisters the enqueued jquery script, the problem is that this doesn’t account for scripts that include jquery as a dependent script. So for example in contact form 7 view the following line of code.
file: contact-form-7/includes/controller.php line 196
wp_enqueue_script( 'contact-form-7', wpcf7_plugin_url( 'includes/js/scripts.js' ), array( 'jquery', 'jquery-form' ), WPCF7_VERSION, $in_footer );
Even though jquery has been deregistered, when wp sees that it is a dependent script in the enqueued contact-form-7 it re-enqueues jquery to be added. Thus we get both WP core’s version and H5BP’s version.
I have resolved this in Bannerspace by writing a plugin that deregisters the bannerspace actions, and then adds it scripts back in without the dependency. I am working on doing the same for contact-form-7, but its a pain to have to do this for any plugin that has this issue. Especially when declaring jquery as dependency is considered good practice, and many plugins will likely continue doing it.
Thoughts?
- The topic ‘Deregistering Jquery doesnt account for enqueued dependencies cause double load’ is closed to new replies.