Skip to content

Embed jQuery Migrate

Milan Petrovic edited this page Aug 11, 2022 · 1 revision

Embed jQuery Migrate

This is a similar code as the one used for the jQuery - Embed jQuery, and it shares some of the code and exactly the same approach.

And while the embedding of JavaScript inside the main HTML content is not recommended, embedding jQuery is one solution to the render-blocking issue.

Pros to the embedding of jQuery Migrate in HTML

  • jQuery Migrate is no longer render-blocking
  • Faster execution of the page

Cons to the embedding of jQuery in HTML

  • jQuery Migrate can't be cached by the browser
  • It will increase the size of the main HTML by 95KB

How this plugin works

The script is run on the website frontend-only; it doesn't affect jQuery Migrate loading on the admin side. It is loading jQuery that is part of WordPress, and places it in the page HEAD, at the very start of the HEAD tag. After that, it hooks into WordPress default scripts registration code, it finds the jQuery Migrate there and replaces the registered script URL with an empty string. This way, jQuery Migrate is still registered, it will not break any code that depends on it, but WordPress will not print the jQuery Migrate script tag.

Clone this wiki locally