How to provide a safety net against multiple jQuery loading?
-
Hello Team,
I have a question regarding something that as a plugin developer I have been observing for a long time now.
When I developed my plugin, I ensured that plugin JS scripts are loaded having jQuery bundled with WP as a dependency, etc:
wp_enqueue_script('my-script', "script-location", array('jquery'), false);
. I thought if WP offers me something, I better rely on it for consistency.Often, my plugin users turn to me with “…hey, suddenly your plugin is broken … or it does not work”. After inspecting the HTML source of their sites, I discover that other plugins and/or theme loaded jQuery again, in addition to jQuery provided by WP. One time I have seen someone’s site where jQuery has been loaded 5(!) times (3 different versions) by different plugins on top of the one provided by WP.
As a result of that, my plugin JS breaks because JS scope gets messed up.
My question is:
Is there anything I can do to prevent my plugin from breaking up when other plugins load jQuery again and again?Cheers
- The topic ‘How to provide a safety net against multiple jQuery loading?’ is closed to new replies.