Disable jQuery Migrate Loading In WordPress Blog


Read {count} times since 2020

If you run a WordPress blog with all the new stuff (functions) and still WordPress loads the jQuery Migrate on your blog, you will be angry (I know hot it feels). The jQuery Migrate file’s minified version is about 7 KB and the unminified version is about 17 KB. That’s a file you don’t need if your blog’s jQuery functions aren’t deprecated.

What’s jQuery Migrate ?

jQuery Migrate is a JavaScript file that adds the jQuery deprecated functions to the page which makes us to use the deprecated functions of jQuery.

Do I Need It ?

It depends on the jQuery code you’re using on your blog. If you use the deprecated functions, you need jQuery Migrate. If you’re not and is pretty sure that none of the plugins you installed is using it, you can move on to the next part of post.

Know If Blog Has Deprecated Functions

The hardest way is to got to jQuery docs, find functions one by one and look for it in your code. This SO answer has a great info on deprecated functions.

Another way is to first remove jQuery migrate and check the browser console for any jQuery errors. If there is an error saying something like this :

ReferenceError: foo is not defined

then there is a depreciated function in your code. You can find it and remove or you can stop this tutorial itself.

Remove jQuery Migrate

Finally, let’s remove jQuery Migrate. Go to your themes’ functions.php file and add the following code at the end of the file :

/* No JQ Migrate - http://subinsb.com/remove-jquery-migrate-in-wp-blog */
add_filter( 'wp_default_scripts', 'removeJqueryMigrate' );
function removeJqueryMigrate(&$scripts){
 if(!is_admin()){
  $scripts->remove('jquery');
  $scripts->add('jquery', false, array('jquery-core'), '1.10.2');
 }
}

Save the file and close. Now, go to your blog and there won’t be any jQuery Migrate file loaded in the page. You just saved 7 KB.

Show Comments