Don’t use jQuery? Why not?
Everyone once and a while, you see a blog post or website complaining about people using jQuery. There’s a lot of reason for people to say this, but from what I’ve seen, it really boils down to just a few reasons:
- Pure Javascript is faster – In almost all aspects of life, better speed creates better applications.
- Page bloat – jQuery adds anywhere from ~30 Kb to to ~180 Kb, depending on whether you use a production or test version
- jQuery encourages bad code – Since it’s so easy to learn, only amateurs use it and they write bad code
- Real Javascript coders don’t use jQuery – I don’t even know what to say about this
- Licensing issues – Some people are afraid of using third-party libraries, but jQuery is licensed under the MIT License, which is completely open source
- Well… that’s about it
The fact of the matter is, these are all bad excuses. In fact, people who say any of these just don’t understand what jQuery is actually for. Many people think that jQuery exists to replace Javascript, but in reality, it is meant to complement it. jQuery’s main advantages are a low learning curve, small more re-usable code and cross platform compatibility. That last one is the most important.
Think about it this way. People use Java for several reasons. First, it’s easy to learn, much easier than lower-level languages such as C++, C, or even Assembly. It also has reusable packages, such as string and network utilities, so that you don’t have to rewrite that over and over again. Finally, writing an application once will let it run on any operating system (for all intents and purposes), as long as it has a JRE installed on it. Seeing some similarities?
jQuery serves the same purpose as Java, just for the web. It’s much simpler to learn than pure Javascript, it provides tons of simple APIs for DOM manipulation, event binding and handling, AJAX calls, JSON support and tons more. Finally, it supports just about every OS/browser combination. Does your DOM traversal check whether or not the Blackberry browser returns nodes that no longer exist? Sure it could, but jQuery already does. Can you write custom versions of the APIs in jQuery? Absolutely. Will pure Javascript run faster than jQuery. Almost always. But will it check for the tiny browser quirks in between? Probably not. The thing that makes jQuery so great is the fact that you don’t have to worry about this. Tons of edges cases have been found, addressed, and thoroughly tested by the jQuery team and other open source contributors.
Finally, just to address the bad code quality code, jQuery is a lot like PHP. PHP isn’t necessarily a bad language. Well, it is, but that’s besides point. PHP gets an even worse rap because, like jQuery, it has a low learning curve and is a popular choice to begin programming. Unfortunately, many of the amateurs write tutorials which many beginners use as a starting point, so a lot of PHP programmers never learn how to write good code in the first place and the problem repeats itself. However, good programmers can write very good PHP. Facebook, which everyone knows as one of the most visited sites today, used to, and still does to an extent, use PHP. In the same manner, if you follow some jQuery best practices, the code that you produce as a result will be quite fantastic.