How to remove jQuery-Migrate.min.js?

WordPress 3.6+ uses the jQuery Migrate script (jquery-migrate.min.js or jquery-migrate.js) to ensure backward compatibility for any plugins or themes you might be using which use functionality for versions of jQuery older than 1.9. Most up-to-date frontend code and plugins don’t require jQuery Migrate module. In most cases, this simply adds unnecessary load to your site, lower your website speed and wast the server power. So in this tutorial, I am going to explain how to remove jQuery-Migrate from WordPress.

Why and How to remove jQuery-Migrate.
Why and How to remove jQuery-Migrate.

Why does WordPress need jQuery Migrate module

jquery-migrate.min.js was loaded with WordPress in order to support older jQuery functions that some themes and WordPress plugins still use.

Is safe to remove jQuery Migrate script from WordPress?

Yes, you should remove jQuery Migrate from WordPress. Here why.

  • It adds unnecessary load to your site, improves your website speed and wast the server power. If you care about performance, there is no reason to serve an extra JS file.
  • The jQuery Migrate file’s minified version is about 7 KB and the unminified version is about 17 KB. By removing it, the browser will have one less JavaScript file to download and execute. As a result, your site will load faster!
  • Because most up-to-date frontend code and plugins don’t require jquery-migrate.min.js. Unless you are using decade-old WordPress themes/plugins for especially purposes, keep jQuery Migrate module is unnecessary.

If you are unsure if your website loaded jQuery Migrate, you can see this running if you launch Firefox Web Developer/Chrome Devtools console.

Why and How to remove jQuery-Migrate.min.js in WordPress
JQuery MIGRATE-1.4.1-is-installed

As you see the text: JQMIGRATE: Migrate is installed, version 1.4.1 on the picture, it confirms that jQuery Migrate module was loaded.

How to remove jQuery-Migrate.min.js from WordPress

If you’re using old plugins or an old theme that use old jQuery functions, you can check whether your site requires jquery-migrate.min.js by open wp-config.php and add this line of code: define('SCRIPT_DEBUG', true);. That way you can monitor any errors. However, don’t enable this on a production site unless you absolutely need to.
Removing jQuery migrate from WordPress is quite easy. There are two different methods to remove it from WordPress: install a plugin or implement a snippet into the theme’s functions.php file.

Use WordPress Plugin to remove jquery-migrate.min.js

The easiest way to make it done by adding a plugin that helps you remove jQuery Migrate module without change the theme’s code.

  • Go to Dashboard >> Plugins >> Add New.
  • Search for Remove jQuery Migrate
  • Choose the newest or most installed plugin then click Install Now
  • Activate the plugin then follow their instruction.

💡Hint

Remove jquery-migrate.min.js temporarily, and go through your site and test all of your plugins’ features to see if everything still works. If anything on your site breaks, then simply remove these snippets and everything will return to normal.

In the current version, it is loaded whenever the jQuery handle is requested by anything, alongside jquery-core in WordPress. jQuery Migrate is nothing but a dependency of the jQuery script in WordPress, so one can simply remove that dependency. You just need to add the following lines of code to your theme’s functions.php file.

/**
 * Remove/Disable/DeQueue jQuery Migrate in WordPress.
 *
 * @author Nguyễn Đình Quân a.k.a narga.
 * @link https://www.narga.net/how-to-remove-jquery-migrate/
 */
add_action('wp_default_scripts', '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'));
		}
	}
 }

This will prevent the jQuery Migrate script from being loaded on the front end with the standard hook (which outputs ) while keeping the jQuery script itself intact. It’s still being loaded in the admin to not break anything there.
Now, go to your blog and there won’t be any jQuery Migrate file loaded in the page.

📢 Did you know?

  • A snippet is a small chunk of PHP code that you can use to extend the functionality of a WordPress-powered website; essentially a mini-plugin with less load on your site.
  • Code Snippets plugin could help you add code snippets to your functions.php file from WordPress Dashboard without edit it.

Is this article helpful? Let me know in the comment section below.