What is jQuery in WP includes?

What is wp-includes jquery.min.js?

What is wp-includes jquery-migrate.js?

What is jQuery? How to Use jQuery in WordPress?

What is calling jquery?

I just cannot figure out what is calling two jquery scripts in my theme. Even if I turn off all plugins, they’re still being called. I have not enqueued them in my function.php and also not in my header.php or footer.php.

The two jquery javascripts that are being called are:

/wp-includes/js/jquery/jquery.js
/wp-includes/js/jquery/jquery-migrate.min.js

If I am correct, those two js files are “only” loaded by WP itself for use in the back-end(Admin), but not (and WP would not load them if no need for it) in the front-end.

As soon a plugin needs them, they will be loaded (e.g. through a function) in the front-end.

WP does not enqueue jQuery on all pages by default.

What is index.js in WordPress?

The code in index.js holds the actual logic: things like create a button, and when the button is clicked display a popup, and when the popup close button is clicked destroy the popup.

How does jQuery work with WordPress?

jQuery is a library that makes working with javascript easier; and it’s honestly just not necessary to use jQuery anymore as it once was in the past. Today all the browsers support fetch() to make XHR requests but back in the Ancient Olden Days you needed a method.

jQuery provided a single method: $.ajax() so that developers didn’t have to write their own make-XHR-request wrapper method every time they started a new project. Using jQuery also made other tasks like changing an element’s CSS attributes easier as you didn’t have to write browser detection code and apply the changes differently for different browser engines.

But for the most part jQuery just isn’t necessary anymore, it’s becoming more and more an artifact. It has its uses, but the things that jQuery was created to fix are now just standard browser features.

jQuery is often a dependency, don’t use it unless you absolutely need to.

jQuery can usually be replaced with vanilla JS now. If you’re making a new code base in 2022, you’re not going to use jQuery. So yes very much dying but not totally dead at this point.

Performance impact of using jQuery in WordPress themes

While it has been widely known that you might not need jQuery for most of your interactive theme features, jQuery is still a common JavaScript dependency found in WordPress themes. TL;DR it has a significant negative impact on performance. jQuery usage in themes correlates with worse LCP performance. Removing jQuery may lead to 80% less JavaScript load. Migrating away from jQuery extensions.

How to disable jQuery on WordPress?

;;;

How to Disable jQuery Migrate in WordPress?

jQuery Migrate script is a useful feature of WordPress that enables developers to upgrade from older versions of jQuery to new ones. It serves as a backward compatibility fix. jQuery Migrate identifies deprecated features and restores them, enabling older code to run on the current jQuery version without a hitch.

Various WordPress versions include the jQuery Migrate plugin on the front-end of your site.

However, most plugins and front-end code don’t require jquery-Migrate.min.js. So this means it’s unnecessary and may slow down your site

If your site is using plugins that run on older jQuery code, it may be prone to security attacks, so it is better to switch to alternative plugins that are kept updated.

Simply install the Remove jQuery Migrate plugin, and it automatically removes the Migrate script from your site’s front end.

Otherwise, in your theme functions.php file, add the following code.

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' );

This will prevent the jQuery Migrate script from being loaded on the front end while keeping the jQuery script itself intact. It’s still being loaded in the admin to not break anything there.