Disable jQuery Migrate in WordPress

Disabling the jQuery Migrate module in WordPress can speed up the loading speed of the web page on the client side while improving its SEO performance.

What is jQuery Migrate?

The jQuery Migrate module (jquery-migrate.min.js) is a javascript library that allows you to preserve the compatibility of your jQuery code developed for versions of jQuery older than 1.9. JQuery Migrate also allows developers to detect deprecated code that is no longer supported by the latest jQuery libraries and to adapt it according to the newest versions of jQuery 1.9 and higher.

Why disable jQuery Migrate?

The jquery-migrate.min.js file has a size of 11 K that requires a download and an additional DNS request from the client side. If your jQuery code and plugins are compatible with the latest versions of the jQuery library, you do not need to use this module and it is best to disable it to avoid downloading it from the client side unnecessarily And thus improve the SEO performance of your web pages.

PHP code to disable jQuery Migrate

Here is the PHP code that allows you to disable jQuery Migrate in WordPress. Simply copy and paste this PHP code into the functions.php file of your WordPress theme and you're done.

functions.php
init 3 wp_default_scripts 12 wp_enqueue_scripts

PHP Code Features

  • wp_default_scripts Filter: We inject this code into the wp_default_scripts filter, which is executed before the wp_enqueue_scripts action hook, the step where jQuery Migrate is loaded among other javascript codes.
  • Anonymous Function: Using an anonymous function rather than a named function, saves memory in the Global Namespace, which is already heavily loaded by WordPress and third-party plugins. WordPress itself loads thousands of functions and PHP variables for processing each single Web request. And since this function needs to be executed only once during the client's request processing, why keep it in memory?
  • PHP Memory Release: Finally, we use the PHP unset($af) instruction to remove from memory our dynamically created anonymous function. By saving our anonymous function in a global variable $af, allows us to delete it at a later step since anonymous functions are not eliminated immediately after their usage by the PHP Garbage Collection system.

Disable jQuery Migrate with one click

The high-performance WordPress theme APACE allows you to disable the jQuery Migrate as well as several other WordPress optimization settings with just one click, see image below:

Comments