I have a few questions relating to WordPress loading / unloading up javascript tools. After reading a nicely written response to a question by Pieter Goosen, that got me to do a bit of studying and a clean up of the code I'm using to load up my libraries. This code is from my child-theme's function.php file. I've got a few functions on my site that use the datepicker calendar tools. Additionally there are a few plugins that I'm sure use jQuery.
function jquery_loadup() {
//wp_deregister_script('jquery'); <--- ?H
wp_enqueue_script('jquery');
//wp_enqueue_script('jquery-migrate');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css');
}
add_action('wp_enqueue_scripts','jquery_loadup');
I was under the impression that the line wp_deregister_script('jquery')
essentially resets/clears all previous 'requests' for the jquery scripts so they don't interfere with one another. That line followed by wp_enqueue_script('jquery');
should result in a minimal clean load of jQuery via the WordPress commonly used scripts registered handle / script paths system, no? I would think that the deregister call tests for the presence of a previous 'install' for jquery, and if it finds one or more, stops their loading, if none are registered, do nothing.
What I'm seeing is that when I use the wp_deregister_script('jquery')
I'm get an error on the websie "ReferenceError: jQuery is not defined"
. When this happens, all of my JavaScript functions fail. What the heck? When remarked out, the site functions fine.
Questions: Am I missing something? What am I not understanding about the deregister call? Why would I be getting an error message?
Note, the line in there for jquery-migrate
is supposed to be for software using older versions of jQuery. I tested it, but I can't see that it does anything on my site, so I've taken it out to improve download and response times. Question: Is that a bad idea?
references: