jQuery 2.0 Beta 2 Released

Posted on by

The next beta of jQuery 2.0 has arrived! This beta has several changes and tweaks based on the feedback we received from those of you who generously tested the first beta. We really need you to test this version as well and let us know what still needs to be done. We believe this version is very stable and ready for you to try; don’t wait until the final release and then find out your code doesn’t run with it.

Remember that jQuery 2.0 will not run on IE 6, 7, or 8; we’re saving that duty for jQuery 1.9. We fully expect that most Internet web sites may continue to use jQuery 1.x for quite a while, as long as older versions of IE still comprise a large proportion of web surfers. And so the jQuery team will also continue to support both the jQuery 1.x and 2.x lines. Don’t feel like you’re missing something or falling behind by using 1.9 on your web site, since the APIs for 1.9 and 2.0 are the same.

If you’d like to try jQuery 2.0 on web sites where you still need to support IE 6, 7, and 8, you can use conditional comments. All browsers except old IE will get the second script and ignore the first:

<!--[if lt IE 9]>
    <script src="jquery-1.9.1.js"></script>
<![endif]-->
<!--[if gte IE 9]><!-->
    <script src="jquery-2.0.0b2.js"></script>
<!--<![endif]-->

There are lots of other environments where jQuery 2.0 should fit in very well. Here are a few suggestions:

  • Google Chrome plugins
  • Mozilla XUL apps and Firefox extensions
  • Firefox OS apps
  • Chrome OS apps
  • Windows 8 Store (“Modern/Metro UI”) apps
  • BlackBerry 10 WebWorks apps
  • PhoneGap/Cordova apps
  • Apple UIWebView class
  • Microsoft WebBrowser control
  • Cheerio or jsdom with node.js
  • Intranet applications

On the node.js front, the jQuery team now owns the “jquery” and “jQuery” names in npm and will soon be shipping 2.0 releases there.

You can get this latest beta from the jQuery CDN:

http://code.jquery.com/jquery-2.0.0b2.js

To run pre-1.9-era code with jQuery 2.0, you can also use the jQuery Migrate plugin to restore deprecated features from those older versions and/or diagnose compatibility issues. We strongly recommend that you do use Migrate for older code, it will save a lot of time and trouble in debugging.

What’s New

Lots of bug fixes: All the relevant fixes from jQuery 1.9.1 and 1.9.2pre have been incorporated into jQuery 2.0 beta 2. We sadly had to back out some optimizations that aren’t supported by older versions of WebKit such as Android 2.3, but most of those didn’t have a significant size impact. Still, we plan to bring them back as soon as we can! To help us out, anytime you see an old Android phone you can “accidentally” whack it with a hammer.

New .data() implementation: This new code is a complete rewrite by Rick Waldron. It’s smaller, simpler, and much more maintainable than the old code.

Increased modularity in custom builds: You can now exclude all the redundant event shorthands such as .mouseover(...) if you’re willing to use .on("mouseover"...) instead.

Minimal selector engine: Richard Gibson created a small wrapper around the browser’s native querySelectorAll and matchesSelector APIs that can be used as a replacement for the full-fledged Sizzle selector engine. Be aware, however, that there are major differences in the supported selectors and semantics. This minimal engine does not support jQuery selector extensions like :radio or :first for example.

Custom Builds

We’d love for you to try out the custom build system which is based on grunt. The README gives more detail on making a custom build. As of beta 2 you can replace Sizzle with a simple selector engine and exclude css, event aliases, animations, offset, and deprecated functionality such as .andSelf() that has not yet been removed. In addition you can exclude a subset of the script, JSONP, or XMLHTTPRequest transports. That’s right, reject any module in our jQuery reality and substitute your own.

Here is an example of what you can save with modular builds. Let’s say you don’t need the css, offset, dimensions, or deprecated modules and plan to do animations completely via CSS transitions and classes. In addition you only use JSONP via $.ajax(). You’ll use .on() for event management and keep your selectors simple so that the minimal selector engine can do the job. The build command to do that is:

grunt custom:-sizzle,-css,-event-alias,-effects,-offset,-dimensions,-deprecated,-ajax/xhr

The resulting file from that custom build is just 17,530 bytes when transferred by gzip, which is 40 percent smaller than the full 2.0 build at 29,387 bytes gzipped. For comparison, the current 1.9 branch is 32,770 bytes gzipped.

We still think that the vast majority of jQuery users are best served by the simplest option: Use the full version of jQuery, served from a CDN or your local server. Most jQuery plugins are not written in a way that would allow you to use a subset of jQuery core functionality — after all, they never anticipated any of it would be missing! But for situations where it’s worth the time to determine those dependencies, jQuery’s current level of modularity offers awesome flexibility.

Many thanks to the people who contributed fixes to this release: Adam Coulombe, Andrew Plummer, Danil Somsikov, Dmitry Gusev, Isaac Schlueter, James Burke, Jean Boussier, Julian Aubourg, Karl Sieburg, Mark Raddatz, Mike Sherov, Nguyen Phuc Lam, Oleg Gaidarenko, Pascal Borelli, Richard Gibson, Rick Waldron, Ryunosuke Sato, Timmy Willison, and Timo Tijhof. Special recognition to Scott González for his minimalist work simply titled, “Whitespace“.

Changelog

Ajax

Build

Core

Css

Deferred

Effects

Event

Manipulation

Selector

Support

Traversing

37 thoughts on “jQuery 2.0 Beta 2 Released

  1. Esteban Saa on said:

    This is great news specially for mobile developers. Parsing times will hopefully be cut in half with this release.

    I’m hopping the JQM team will make the best use of this new custom build system and make it work with their own custom build system. So that we can generate a single and more efficient peace of code.

  2. Ben Squire on said:

    Is it me or do the conditional statements above mean IE9 doesn’t get jQuery at all??

  3. @Ben Squire: gte means “greater than or equals”, so IE9 gets jQuery 2.0 with this conditional statement

  4. Binyamin on said:

    You still can’t compare Zepto.js and jQuery 2 file size, 10.9?KB vs 29.1?KB compressed gzipped file size. jQuery is almost 3x bigger.

  5. River on said:

    @Binyamin: What do you think is in that difference? Zepto would have a similar size if it addressed the issues the jQuery community fixed over the years. Filesizes like this should be a non-issue, stability is what matters.

    If Zepto sticks around, it’ll just grow to similar filesize. I doubt it will though because people know better. Do yourself a favor and go for something stable.

  6. MAddy on said:

    The difference between jquery 1.9 and 2,0 is less than 3.4 KB (gzipped). For such a small difference, is it worth maintaining two version? Thank you for all your hard work :)

  7. @MAddy: they’re not done, but anyway, it’s not only about file size, but also about performance and maintainability.

  8. I’m reading my email repeating to myself “I don’t have time for that” and pressing delete. I said to myself, “About the only thing I’d make time for is is jQuery came out with a 2.0 version…”

  9. Arturo on said:

    I’ve been preferring microjs.com stuff (and TJ Holowaychuk’s components) a lot lately because of size and modularity, though jQuery is the only thing that gives you cross-browser peace of mind when doing client work and you just need to deliver. So this 2.0 (and everything new in it) sounds like the right thing at the right time.

  10. Finally there is jquery 2. It has been long journey and through JQ learned JavaScript. Thank you for your good work!

  11. Martijn on said:

    “Remember that jQuery 2.0 will not run on IE 6, 7, or 8”

    Also remember that this is a VERY bad decision. Now is not the time to ditch IE7 and IE8. Ditching IE6 is ok, but IE7 and IE8 are still in use, and customers demand websites to (at least) work on them. Web developers may decide not to have their sites work on IE8, but jQuery must not make this decision for everyone at once.

    So, ditching support for the newest IE that runs on Windows XP (which is IE8) is a horrible decision, iyam. And one that will prevent many (if not all) commercial users of jQuery from upgrading to 2.x.

    Sorry, this is all I can (and will continue to) say about jQuery 2.0.
    Ditch IE6 but support IE7 and IE8, and you will have my respect once more.

  12. @Martijn, please re-read what we have said regarding jQuery 1.9 and 2.0 until you understand that we are not “ditching” anything.

  13. Martijn on said:

    @dmethvin
    Yes I read it, using two different versions of jQuery. Welcome to hell. No way I’m doing that.

  14. @martijn:
    “Don’t feel like you’re missing something or falling behind by using 1.9 on your web site, since the APIs for 1.9 and 2.0 are the same.”

    There you go. They are not forcing you to use 2 versions, IE6,7,8 are supported with a fully functional version of jquery. jQuery 2.0 is only for people for whom absence of IE support is not a problem, but higher size / complexity / slowness might be an issue (e.g. WebView in a mobile application).

  15. Also remember that XP is about a year away from being completely out of support too, with Server 2003 to follow in only a year afterwards.

  16. Herbert Peters on said:

    @ Robert McLaws
    It does work as published if you try it out. Carefully check the extra comment tags in the gte IE9 section.

  17. Ernest Burnett on said:

    Very much agree with @martjin. We just got rid of doc types, now we are going to need standardization for javascript and jquery. WordPress is updating on the 29th, anyone consult with them on what libraries they will be supporting within their framework? Goes on and on and on for the countless integrations. I don’t want to carry around 2 versions – or have to remember which one is required to do what, you’ll never be rid of 1.9.x – and setting yourselves up for failure.

    Robert’s illustration demonstrate’s exactly this – while conditional comments not applying to IE10+, not exactly the smartest thing to do. If you have IE10 installed, I can imagine it would be very difficult to test working scripts and lte/gte comments.

  18. Too bad “grunt” doesn’t actually work at all:

    path.js:313
    throw new TypeError(‘Arguments to path.resolve must be strings’);

    ..seen this for weeks now. Fun times.

  19. Basavaraj on said:

    I am using 2.0 in my phonegap app and want to go live by early May

    What do you guys think? i am going to package 2.0 in my build instead of referring to CDN

    Also what is the 2.0 release targeted?

  20. @ernest, I read the reply and am not sure what you’re trying to say. You can safely use 1.9 for all browsers if it seems too hard to decide or understand. We’re not forcing anyone to use 2.0 or conditional comments.