To optimize website loading speed, one point is to reduce the number of website resource requests. For websites we build using WordPress, a jquery-migrate.min.js JavaScript library is referenced by default. Usually, we can disable the reference to this Jquery Migrate file to reduce one resource request. Let's take a look below.
How to disable jquery-migrate.min.js.
Introduction to jquery-migrate.min.js
jQuery Migrate is a JavaScript library that enables compatibility with jQuery code below version 1.9. It has been included in website loading resources by default since WordPress 3.6. Most plugin or theme code from newer versions do not require jquery-migrate.min.js, so if you are sure your website does not have very old code that needs this js file, you can disable it to avoid loading it on the frontend.
Methods to disable jquery-migrate.min.js
You can use a plugin to disable it, or use code to disable it. Considering the code method is very simple, using a plugin is not recommended. However, if you don't know how to modify code, you can install a code modification plugin to help you, as its functions are often needed.
Safe method to add code to the functions.php file: Code Snippets The specific disabling code is as follows://移除jQuery Migrate脚本
//https://blog.naibabiji.com/news/jin-yong-jquery-migrate-min-js.html
function dequeue_jquery_migrate( $scripts ) {
if ( ! is_admin() && ! empty( $scripts->registered['jquery'] ) ) {
$scripts->registered['jquery']->deps = array_diff(
$scripts->registered['jquery']->deps,
[ 'jquery-migrate' ]
);
}
}
add_action( 'wp_default_scripts', 'dequeue_jquery_migrate' );Adding the above code to the theme's functions.php file can prevent the jQuery Migrate script from loading on the frontend, while keeping the jQuery script itself intact. It still loads in the admin dashboard and won't break anything.
More articles related to WordPress optimization:
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.