5

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.

10
  • Sounds like you did not fix everything if it breaks without it. What are the errors are you seeing when you remove it? Commented Oct 25, 2017 at 20:56
  • So, what is going wrong? What is not working and what is in the console? Maybe that could shed a hint on why the page doesn't work as expected anymore
    – Icepickle
    Commented Oct 25, 2017 at 20:56
  • 2
    jQuery Migrate's purpose is to allow you to use deprecated features while still using a newer version of the library. It's not just a "behind the scenes" thing. It will log when you are using deprecated features but the intent is to allow you to use newer libraries without removing code that has been removed from the newer libraries.
    – steve v
    Commented Oct 25, 2017 at 21:00
  • 1
    It's kind of both, the console.logs help you clean up while the workarounds let you maintain functionality until you cleaned up your code. Commented Oct 25, 2017 at 23:29
  • 2
    You should be looking for size().....not the full string... and $.browser is probably the other thing to look at.... Commented Oct 26, 2017 at 1:18

1 Answer 1

4

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.

6
  • When I see JQMIGRATE: jQuery.browser is deprecated in the console, it points to this file: jquery-migrate-1.4.1.js. I searched for $.browser and I can see that it is used in some of my plugins. Why is it that when I see in the console JQMIGRATE: jQuery.browser is deprecated, it does not point to the files containing the plugins where the deprecated $.browser is used? It would be more useful than pointing to jquery-migrate-1.4.1.js. I already know and it is obvious that if JQMIGRATE is complaining into my console, it is because the jquery-migrate-1.4.1.js utility was used. Commented Oct 26, 2017 at 21:31
  • The information you are looking for would be in the stack trace but this information is not available to JavaScript code (you can throw an exception and the browser will build a stack trace for debugging, but you can't write JS code that inspects that at runtime) so this is just the next best alternative. Commented Oct 26, 2017 at 21:36
  • 1
    See this image: imgur.com/a/uAThZ Apparently it is already telling me where $.browse is used in my plugins. Is that the stack trace you are referring to that is not available to JavaScript code? Commented Oct 27, 2017 at 0:48
  • 1
    And now I just learned about console.trace That is going to come in handy :) Commented Oct 27, 2017 at 3:29
  • 1
    Apparently you could can add browser detection back into jQuery pupunzi.open-lab.com/2012/08/14/… Commented Oct 27, 2017 at 3:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.