Home Experience & Tips Sharing Standard Post

Standard Post

WordPress Optimization Tips: Disable Jquery Migrate File

To optimize website loading speed, one point is to reduce the number of resource requests. Our WordPress website by default references a jquery-migrate.min.js JavaScript library. Usually, we can disable this Jquery Migrate file to reduce one resource request…

Updated on January 2, 2020 About 3 minutes reading
WordPress优化小技巧,禁用Jquery Migrate文件

To optimize website loading speed, one point is to reduce the number of resource requests. Our WordPress website by default references a jquery-migrate.min.js JavaScript library. Usually, we can disable this Jquery Migrate file to reduce one resource request.

Let's take a look belowHow to disable jquery-migrate.min.jsnow.

Introduction to jquery-migrate.min.js

jQuery Migrate is a JavaScript library that enables compatibility with jQuery code below version 1.9. Since WordPress 3.6, it has been included by default in the website's loaded resources.

Most new versions of plugins or themes do not require jquery-migrate.min.js. So if you are sure that your website does not have any old code that needs this JS file, you can disable it to prevent it from loading on the front end.

Methods to disable jquery-migrate.min.js

You can disable it using a plugin or by code. Considering the code method is simple, using a plugin is not recommended. However, if you are not comfortable modifying code, you can install a plugin that helps with code modifications, as its functionality is often useful.

Safe Method to Add Code to the functions.php File: Code Snippets

The specific code to disable it 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' );

Add the above code to the functions.php file of your theme. This prevents the jQuery Migrate script from loading on the front end while keeping the jQuery script itself intact. It still loads in the admin area and won't break anything.

More articles related to WordPress optimization:

4/5 - (1 vote)
Previous B2B Website SEO Has No Ranking? Check If You Have These Issues Continue reading content around the same timeline. Next How to Add CSS in WordPress View the next related tutorial or experience.

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: