Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need jquery-migrate-1.4.1.js after a successful jQuery upgrade?

Tags:

I am done upgrading jQuery from 1.3.1 to 1.12.4. Everything is working correctly and I am ready to remove jquery-migrate-1.4.1.js because I was only using it for debugging purposes during the upgrade process.

When I remove jquery-migrate-1.4.1.js from the <head> section of my website, the page does not work properly anymore. Something breaks in the JavaScript/jQuery. I was reading https://blog.jquery.com/2016/05/19/jquery-migrate-1-4-1-released-and-the-path-to-jquery-3-0/ trying to find information about it, and this is something I found:

Remove the Migrate 1.x plugin and ensure the page still works properly without it loaded.

Why do I need jquery-migrate-1.4.1.js after a successful jQuery upgrade? I thought it was only a "behind the scenes" script for debugging purposes exclusively, not to maintain any jQuery/JavaScript functionality.

like image 977
Jaime Montoya Avatar asked Oct 25 '17 20:10

Jaime Montoya


1 Answers

The misunderstanding that is tripping you up at the moment is that the purpose of jquery-migrate-1.4.1.js is to install a few backward focused workarounds to make early jQuery code work in the more up to date jQuery while also complaining into your console.log so you can fix it. It is not actually changing your code. A couple of pointers to help you migrate based on your comments:

I see for example: "JQMIGRATE: jQuery.browser is deprecated". That is odd though, because the source of that error is jquery-migrate-1.4.1.js:45 and that is the jquery-migrate-1.4.1.js file, not that I am using jQuery.browser in my code.

The line doing the logging is in the jquery-migrate-1.4.1.js so the error appears to point to that file, however, the line calling jQuery.browser might be in a plugin you are loading (this was common in early jQuery days where people wrote browser-specific hacks) You can try and search for .browser in all of your linked .js files (even the minified ones) to at least isolate the plugin and then try to find alternatives.

I see things such as: "jquery-migrate-1.4.1.js:45 JQMIGRATE: jQuery.fn.size() is deprecated; use the .length property". But I cannot find jQuery.fn.size() in my source code.

The approach of jQuery.fn.size() might show up in your code like this:

$('li.items').size()

jQuery.fn is just the object name of a jQuery element's functions. Because your jQuery object is based on a jQuery selector you wrote it might be hard to search for it, instead look for something like .size() and if it shows up to the right of a jQuery selector then try and replace it with just .length (no parentheses, as length is just a property).

If you have other questions you are probably better off posting them as new questions so they can get more direct and generally helpful answers.

like image 160
Jason Sperske Avatar answered Oct 04 '22 00:10

Jason Sperske