Migrate.js – How do I remove jQuery Migrate from WordPress?
jQuery Migrate is a JavaScript library. This ensures the compatibility of older versions of jQuery (older than 1.9). This restores obsolete features and behaviors in the jQuery code and continues to execute properly. As of WordPress 3.6, jQuery Migrate is automatically included on all WordPress installations.
If current designs and plugins are used in WordPress, jQuery Migrate is not required, so the script can be safely removed. If you remove it, the browser will have to download and run a JavaScript file less. Your website will load a little faster again!
If you keep your jQuery code up-to-date and are sure that none of your plug-ins are incompatible with jQuery 1.9 or jQuery 1.10.2, jQuery Migrate can be easily removed.
In the Chrome Devtools console, you can check if the script is still running.
# 1: Reasons why it’s a good idea to remove jquery migrate from WordPress
1. Avoid an additional HTTP call for a JS file that is not needed.
2. Keeping code, themes and plugins up to date is a better idea than loading an additional file for support.
3. You have plugins installed using older jQuery code? It is more effective to update or change to an alternative.
# 2: How do I remove jQuery migrate from WordPress?
Removing jQuery migrate from WordPress is simple. Just add the following lines of code to the file: function.php of your theme or your child theme.
//Remove JQuery migrate
function remove_jquery_migrate($scripts)
{
if (!is_admin() && isset($scripts->registered['jquery'])) {
$script = $scripts->registered['jquery'];
if ($script->deps) { // Check whether the script has any dependencies
$script->deps = array_diff($script->deps, array(
'jquery-migrate'
));
}
}
}
add_action('wp_default_scripts', 'remove_jquery_migrate');
Alternative:
Another easy way is to disable it using the “Remove jQuery” Migrate plugin. If you’re not sure if your website still requires jQuery Migrate, you can add the following line to your wp-config.php and watch the console as you search for logs on your site. Then remove the line from the wp-config.php and test if everything is working properly. Think about deleting caches (browsers, plugins, servers, etc.). Now the load time of the website should be a little faster.
define('SCRIPT_DEBUG', true);
Conclusion:
As mentioned earlier, jQuery migrate adds an unnecessary load to your site. Therefore, I recommend removing it from your website or WordPress blog. If you need help, let me know.