Tuesday, January 22, 2013

Migrating to jQuery 1.9


jQuery 1.9 was released on the 15th of January 2013 and along with it a few changes.
Migrating to 1.9 is different than with previous versions due to the removal of deprecated features, making the new release smaller and cleaner.

So how do you go about migrating to jQuery 1.9?


Content


1.9 / 2.0 and IE support clarified


I want to go over this one first as I feel the topic of jQuery 1.9/2.0 and IE 6, 7 and 8 support was/is most discussed, most misunderstood and something at least a few seem to worry about.

Though this one is not a change in jQuery 1.9 but jQuery 2.0, some seem to have thought it was either part of 1.9 or effected it somehow. Therefore I decided to include it.

  • jQuery 1.9 will continue support for IE 6 and later
  • jQuery 1.9 will continue to be maintained alongside 2.0
  • jQuery 2.0 is the release which will no longer support IE 6, 7 or 8
  • If you want/need to support legacy IE, use 1.9 if you don't want/need to then use 2.0

As stated in a jQuery blog post from the 15th of January 2013 (The state of jQuery 2013):

First of all, let's be very clear: The jQuery team does "worry" about IE 6/7/8, with jQuery 1.9.
We've created a legacy-free jQuery 2.0 in order to address the many situations where older versions of IE aren't needed.
Some glorious day in the future, jQuery 2.0 will be the only version you'll need; until then we'll continue to maintain jQuery 1.9.

Either way jQuery 1.9 is good to go and if you like you can also keep an eye on the 2.0 Beta which was also released on the 15th if January 2013.

I hope this clarified some of the questions around this topic. Though feel free to leave a comment if something is still on your mind regarding IE support.

If you want to have more background and information about 1.9 and 2.0 in this context I have the links to the relevant jQuery blog posts in the additional resource section at the end.
back to top

Deprecated, Deprecated, Gone!


One of the changes in jQuery 1.9 was the removal of any of the features previously marked as deprecated, such as live() for example.

For a long time now it was advised to not use deprecated methods and when writing any new code using 1.7 or later to not use them but instead use the alternatives noted in the online documentation.

Also, in a jQuery blog post from the 28th of June 2012 (jQuery Core: Version 1.9 and beyond) in regards to the planned 1.9 release, it was mentioned:

jQuery 1.9 (early 2013): We'll remove many of the interfaces already deprecated in version 1.8; some of them will be available as plugins or alternative APIs supported by the jQuery project.
IE 6/7/8 will be supported as today.


back to top

Migrating my code to 1.9


Though we had plenty of warning that deprecated methods will be removed not everybody could have been aware of this for various reasons.

Shortly after the 1.9 release some minor panic struck within some of the development forums, when developers upgraded to 1.9 and found themselves looking at console messages similar to those:
Uncaught TypeError: Object [object Object] has no method 'live'
Uncaught TypeError: Object [object Object] has no method 'die'
Luckily jQuery provides us with support to migrate existing applications to 1.9 with the release of jquery-migrate-1.0.0.js
The migrate file contains the deprecated methods and by including it your code will work again.

However, in addition you will now see warning messages in your console, letting you know that you are using a deprecated method similar to those:
JQMIGRATE: jQuery.fn.live() is deprecated
JQMIGRATE: jQuery.fn.die() is deprecated 
For existing project migration to 1.9
Use the migrate file. This will make sure your code will still work in 1.9.
Off course, the intention is that you go through the warnings and over time replace the methods with the proper ones.

Some replacements are straight forward such as replacing live() with on().

Others can be more complex such as replacing the deprecated mouse-event toggle(handler, handler, ...) with a custom toggle implementation.
One of which is mentioned here on the jQuery forums: Toggle deprecated, what to use instead?

For any new projects
Do not use the migrate file. Work only with the latest methods and any issues can be quickly addressed between the browser debugging tools and the jQuery online documentation.
Also, the release note on the jQuery blog are very good. I have them linked below under additional resources.
back to top

Additional Resources


Throughout the post I mentioned a few jQuery blog posts and other resources which you can find links to below:
Feel free to comment if you had any issues migrating to 1.9, if you want to add to any of the above, noticed any wrong information or if you simply want to share something else within the scope of jQuery 1.9/2.0.

Happy Coding.
back to top

1 comment :

  1. Good information--I was not aware of the migrate file. Thanks!

    ReplyDelete