In the last 2 or 3 years, we have all experienced the comeback of javascript. A language cursed in many ways, for its lack of consistency across browsers, slow runtime performance and poor tooling (debugging). The revival of Javascript is hard to miss though, given the jungle of frameworks and effects libraries that are becoming available. Even browser manufacturers are jumping on this trend by delivering javascript engines that dramatically speed up javascript execution. Javascript "2.0" seems to be the fuel for the next generation of web applications.
For long I have more or less ignored this whole trend. Most developers have enough new things to learn already, and javascript is often not the top priority. The fact that there are a lot of different frameworks (MooTools, Dojo, Prototype, jQuery, etc) does not make it any easier either.
Below are my 7 reasons why you should learn a javascript framework, and that the best one to learn about is jQuery.
1. jQuery seperates behavior from markup
In HTML markup it is still quite common to see things like this:
<form id="myform" onsubmit=return validate();" >
Even though the validate() function can be placed in an external file, in effect we are still mixing markup with logic and events here. jQuery allows you to completely seperate the two. With jQuery, the markup would look like this:
<form id="myform">
Next, the seperate JS file will contain the following event subscription code:
$("myform").submit(function() {
...your code here
)}
This allows for very clean markup with a lot of flexibility. jQuery takes javascript out of your markup, much like CSS took the style out of markup years ago.
2. Write less, do more
Write less, do more - it is the jQuery slogan, and it is an accurate one. Using jQuery's advanced selectors, you can do amazing things in just a few lines of code. You do not need to worry about browser differences (much), there is full Ajax-support and many other abstractions that make you more productive. jQuery takes javascript to a higher level. Here's a very simple example:
$("p.neat").addClass("ohmy").show("slow");
That little snippet loops through all <p> elements with the class "neat" and then adds the class "ohmy" to it, whilst slowly showing the paragraph in an animated effect. No browser checks, no loop code, no complex animation functions, just one line of code!
3. Performance
Out of the big Javascript frameworks, jQuery understands performance best. The minimized and gzipped version is only 18K in size, despite tons of new features in various releases, this number has hardly changed. With each release, major performance improvements have been made. This article is telling of the raw speed of jQuery and the focus that their developers have on it. Combine this with the new generation of browsers (Firefox 3, Google Chrome) that have fast javascript engines on board, and you have a whole new wealth of possibilities in creating rich web applications.
4. It is a "standard"
JQuery is not an official standard, let that be clear. However, the industry support for jQuery is overwhelming. Google uses it, and even hosts it for you. Dell, Digg, Wordpress, Mozilla and many others use it too. Microsoft is even shipping jQuery with Visual Studio. With so much weight behind this framework, you can consider it a safe choice for the future, and a safe bet to invest time in.
5. Plugins!
There are thousands of plugins developed on top of jQuery. You can use it for form validation, galleries, field hints, animation, progress bars, you name it, it is available. The jQuery community is an eco-system, not just a library. This further supports reason #4, it is a safe choice. By the way, did you know that jQuery actively works together with their "competitors", such as Prototype. It looks like they're here to improve the overall state of javascript, not just for their own benefit.
6. It costs you little time
Of course it will cost you time to truly learn jQuery, especially if you will be writing lots of code or even your own plugins. However, you can do this in bits and pieces, there are tons of examples out there and it is really easy to get started. My advise is to first have a look in the plugin pool before you code something yourself. Next, have a look at the actual plugin code to see how it works. In short, learning jQuery is no huge investment, you can be productive right away and increase your skill in small increments.
7. Fun
I found working with JQuery to be a lot of fun. It is fresh, short and you quickly get results. It solves many nagging javascript problems and annoyances. I used to hate javascript coding but (somewhat) enjoy it now. With the basics fixed, one can now really think about developing next-generation web applications, without being slowed down by an inferior language or tool. I believe in the "Write less, do more" slogan.It is true.
What is not good about jQuery
Of course jQuery is not perfect. So far, I have experienced the following jQuery caveats:
- Not backwards compatible. Each new release is not by definition backwards-compatible with earlier releases. For example, sometimes some kind of selectors are deprecated. Instead of keeping them supported, jQuery simply removes them from the new release. This can break your code or that of plugins.
- Plugins-compatibility. Related to the previous point: when there is a new jQuery release and you want to upgrade, it will depend on your plugin author whether you can upgrade. Quite often existing plugins will break in the newest jQuery release. The more plugins you use, the bigger the chance this will happen. I once fixed a 3rd party plugin because I wanted to upgrade to jQuery 1.3, so you do not always have to wait for others.
- You can quite easily come in a conflicted state when you use multiple plugins on the same page, particularly when they tie to the same event or selectors. This is not due to jQuery itself, but still a problem that is hard to debug and fix.
- JQuery does not leave me with an impression of stability. It does not crash my browser, I'm talking about their release policy. Just days after the major new release 1.3, a bug fix release 1.3.1 was released. They also remove functionality that they classify as deprecated, potentially breaking a lot of code. I'm hoping these kind of breaking changes will be limited in the future.
- Out of the big frameworks, the jQuery core library has relatively poor support for animation and effects. However, in practice this is not problem at all. There is a seperate jQuery UI project and tons of plugins for these kind of things.
Conclusion
My opinion is that if you have these questions:
- Should I learn a javascript framework?
- If so, which one?
My answers would be "yes", and "jQuery". This is not to say the other frameworks are not good, it's just that jQuery looks like the most safe and rewarding investment of your time.
Do you agree?
If you liked my post then,
Click here to Subscribe to FREE email updates from "itrickz", so that you do not miss out anything that can be valuable to you and your blog!!
1 comments: on "7 reasons why you really should learn jQuery »"
"...I once fixed a 3rd party plugin because I wanted to upgrade to jQuery 1.3..."
as you should, giving back to the community keeps it alive.
Post a Comment