Why discourage using jQuery?

Hi guys,

I noticed many of you here discourage using jQuery?
As far as I know the purpose of jQuery is Code Less, Do More.

So please can you guys explain why you prefer using pure JavaScript than using jQuery?
I want to know the reasons why?

Thanks in advance.

Primarily it’s because the people providing help and assistance here should not promote a personal preference towards libraries. This is why you don’t find people pushing YUI or Dojo or MooTools etc. If anyone was to do so, there would be umbrage from the general community, and the same applies to jQuery too.

There can also be times when you may want someone to realise that what they’re wanting to achieve may be easier to do by using a certain library, or external resource. By all means mention that, but if you do then you must approach that idea with the understanding that they may not want to take that idea onboard.

If someone says that they are currently using jQuery, or some other library, that then is a good time to start applying techniques from that particular library.

To be able to use JQuery (or any of the other frameworks) properly you need to have an intermediate level knowledge of JavaScript first. Most of the people having problems with the frameworks are having those problems due to too little knowledge of JavaScript itself prior to trying to use a framework built on top of it.

Yes JQuery (and the other frameworks) allow you to write less code yourself and do more but only because the framework provides the JavaScript code to do the rest for you. Only once you at least understand the concepts of how to do each of the tasks for yourself using ordinary JavaScript does it make sense to substitute calls to existing functions that contain the code to do it for you. Only at that point can you properly work out which calls to use for what and were using the framework would actually result in writing more code.

I have seen beginners use JQuery with twenty line of code they have written themselves to do JQuery calls where six or seven lines of JavaScript without JQuery calls could achieve the same final result much faster - making JQuery for them - write more to do less - and so defeating the entire purpose of JQuery in the first place.

There’s nothing wrong with using JQuery or another framework to reduce the amount of JavaScript that you write - as long as you know enough JavaScript to use it properly. Most people having problems with JQuery are having the problems due to trying to use it prior to learning enough JavaScript to know how to use it properly. Therefore the appropriate advise in most cases where people are having JQuery problems is to learn more JavaScript.

jQuery is JavaScript. The jQuery motto could just as accurately have been Code Less, Download More. To use jQuery, the browser has to download a big JavaScript library (prewritten code). So before using jQuery, it’s worth asking if it’s really needed, or if it’s really more efficient. You sometimes see people using the entire jQuery library to add two numbers together—something you can do with one line of JS. Another way of looking at it is this: if you need a new hammer, should you go out and buy a whole hardware store?

In all fairness, the library isn’t that big. Version 1 is 90KB and version 2 is 80KB.

If download speed is an issue, it’s sometimes good practice to put all the javascript files near the end of the body to led the HTML and CSS load first, then the javascript.

To echo what the others have said, Javascript frameworks have their place, and you just need to get enough experience with javascript in order to determine when or when not to use the features available to you in a framework.

Typically, I use javascript frameworks for (complicated) DOM retrieval, animation/transition effects, and AJAX. All of these things are implemented in slightly different ways across browsers, so it’s handy just to write code once using a framework to essentially do the same thing in all browsers.

One of the reasons why jQuery is one of the frameworks you typically hear about is because it is one of the most active javascript framework projects with fairly frequent releases and updates.

However, with jQuery, it’s important to note that version 2.x has dropped IE6-8 support. Version 1.x still has IE6-8 support.

Here’s a comparison of the various major frameworks that are available: