Steve Fenton

The novice view of jQuery

I’m not picking on jQuery in particular here. I chose it because it is no doubt the biggest and most widely used example of a JavaScript library. So when I mention jQuery here, be in no doubt that this applies to Prototype, Mootools, and any other framework that makes your JavaScript easier to write.

And you can read “easier to write” in a churlish manner, because JavaScript is as easy as all the other languages you use – the difference is that you actually learned the others.

There are two novice views on jQuery. The first is puppy-dog excitement about it. The second is denial.

Wow Look What jQuery Does!

The most common reason for selecting the dollar-library back in the day was that you wanted to use a drop-down menu script, or a slideshow, or some other plugin. The instructions told you to include jQuery as they depended on it. The plugins were the big sales and marketing force for jQuery, spreading it far and wide. It would not surprise me at all to discover that a large portion of jQuery wielding websites do so just for a couple of plugins. The other route in was that it was often included in boiler-plate code and templates – so people end up starting with jQuery pre-included in their web site or application (even before they decided what the application needed to do).

Very often, though, the excitement will lead to new code being written that uses jQuery. Certainly, back in the day, jQuery was busy smoothing out a whole bunch of browser insanity. It was saving you many lines of code because it had efficient and effective ways of performing the same operation no matter what browser you were using. It is also fair to say that it did make a lot of tasks easier – being able to use CSS selectors to get collections of elements and then running animations on them was amazing. Trying to do it without jQuery was complicated and performed badly. These features were so popular, they are now making their way into the browser, where they can easily out-perform any JavaScript code.

So this is the puppy-dog excitement phase of jQuery. Almost everyone experiences this one.

Enough of the jQueries!

Onto the second novice phase of jQuery, which is denial. There comes a point where you realise that you can write in 10 lines of JavaScript what have been leaning on a thousand-line library for. This may happen when you get more comfortable with JavaScript, or when you discover that CSS and HTML are able to do what you want without any scripts at all. At this stage, jQuery is abandoned in disgust, like a murderer discarding a bloody knife when they realise what terrible things they have done with it.

Open Relationship with jQuery

You need to go through these phases and feel all of the pain before you can move on to a healthy relationship with jQuery. It is a useful library that can be used when appropriate to solve problems. If your blank web template includes jQuery and related ephemera, you’re probably doing it wrong. Equally, if you refuse to use a tool because you have seen other people using it incorrectly, you’re doing it wrong too.

jQuery is the drinking-problem of the World Wide Web. There are people getting utterly smashed on it, throwing up on the streets and shouting at Police officers. Then there are people going tea-total because they got scared of what the alcohol is doing to them.

The path, my friends, is moderation. The novice will look for a rule to aid them in the selection of the right tools – but you’re better than that. Don’t reach for the tools before you understand what you are making. jQuery may have a place in your web site or application, but wait until you know you need it before downloading a whole bunch of JavaScript files and bundling them into your pages.

Written by Steve Fenton on