What is Migrate js and why does WordPress enqueue it?

If you’ve worked on customizing a WordPress site and you are concerned with performance then you have probably noticed that WordPress 3.6+ automatically adds a request for migrate.js. What is migrate js? It’s a jquery library that helps identify or migrate depreciated tags for versions of jquery older than 1.9. The plugin can be included with versions of jQuery as old as 1.6.4 to identify potential upgrade issues via its JQMIGRATE console warnings. However, the plugin is only required for version 1.9.0 or higher to restore deprecated and removed functionality. You can read more about migrate.js on the official jquery site or from the github page

 

 

WordPress seems to automatically enqueue the migrate.js file. If you are anything like me, you are probably careful about the number of http requests on your site. I appreciate the plugin and I am glad that it exists. Especially when debugging your code for deprecated console. The jQuery team wrote this on debugging with migrate.js:

With this development version, warning messages appear on the browser’s console. They all start with JQMIGRATE so they’re easy to find. Just match up each message with its description in the warning list to determine what it means and how it can be fixed.

Typically I have taken the steps to debug and ensure my code base is free of depreciated code or erros before deploying to production. Therefore I don’t really need the migrate.js to be included on production. I subscribe to the idea that it is always better to keep your code, themes and plugins updated than it is to patch in support with an additional files. Here is how I have been removing or dequeueing the request for migrate.js.

Add this to your functions.php file

[code]

//Make sure any external scripts don’t require the functions.

function dequeue_jquery_migrate( &$scripts){
if(!is_admin()){
$scripts->remove( 'jquery');
$scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' );
}
}

add_filter( ‘wp_default_scripts’, ‘dequeue_jquery_migrate’ );

[/code]