In You may not need jQuery (Maybe you don't need jQuery) two cases are distinguished, the use in the application itself and the one of including jQuery as a library requirement. I leave the case of using jQuery as a library requirement out of the scope of this question because otherwise it would be too broad. This question is focused on the use of jQuery in the application itself.
The reference suggests using jQuery whenever possible, however there are questions on Stack Overflow that ask for answers using pure JavaScript.
Today here on Stack Overflow in Spanish there is a question that currently has two answers, one with jQuery and the other with pure JavaScript. This question is not about saying which of the two answers is better, but about better understanding the implications of using jQuery in a web application.
I mentioned above that the case of using jQuery as a library requirement is left out of this question so it's not too broad. I also ask to leave out comparing jQuery with other similar libraries.
In order for responses to qualify as objective and non-opinion based, they must include substantiated methodological/technical arguments focused on the implication of using or not using jQuery.
Translation of the introduction of You may not need jQuery
jQuery and its cousins are great and should of course be used if they make it easier to develop your application.
However, if you are developing a library, please take a moment to consider whether you really need jQuery as a dependency. Maybe you can include a few lines of useful code and waive the requirement. If you're just targeting your library to newer browsers, you won't need anything more than what the browser already comes with.
At the very least, make sure you know what jQuery is doing for you , and what it isn't. Some developers think jQuery protects us from a big browser incompatibility demon when, in truth, post-IE8 browsers are pretty easy to handle on their own.
The answer is NO . When you use a library or framework, the question that comes to mind is:
Obviously, dozens of reasons go through your head and in the end, what motivates you to choose between one or the other are the needs you have. When jquery was born , the way to develop in JavaScript for cross-platform purposes was literally a nightmare, you had to take many things into account and make a code for each browser in most cases. It can be said that jquery was born as a polyfill for IE6.
Since that time things have changed a lot; the committee in charge of the specification started to work, the community started creating many better and better libraries and frameworks; New concepts such as Virtual DOM , reactive programming , data binding , etc. began to be popularized.
In my opinion, jquery for professional-scale modern web development is totally obsolete; some people will disagree, others will. I think that nowadays handling the DOM directly is no longer necessary; in fact, abusing this can reflect negatively on the performance of your application. With jquery you do this exhaustively because it was created for this and, if already manipulating the DOM too much can mean bad performance, using jQuery you reduce the ops/s brutally . Nowadays, new techniques have appeared that offer better solutions that are worth using. The evolution of a technology ecosystem always improves what already exists.
The answer will depend on the scale of the project; for small projects, es6 and higher is enough and more than enough; for medium and large scale projects it is better to rely on an efficient framework that means less development effort/time and a more flexible development model.
The answer can be answered with another question: Are there better alternatives that allow me to do the same thing in a more efficient and dynamic way ?
I think that using jquery also depends on the level of experience you have with javascript ; obviously for a purely backend programmer, using jquery will be much easier than using vue.js or reactjs with redux ; however, if we stick to an objective reality, it is better if, as far as possible, we use alternatives that mean greater productivity and provide us with greater benefits, such as code quality, efficiency, scalability, etc.
The truth is that frontend development has evolved considerably and new solutions to old problems have appeared , more efficient, more compact, more concise solutions; This is why frameworks have been born that are revolutionizing frontend development, such as reactjs or vue.js.
As they say in this world... Use the right tool for the right job .
There are several conflicts in use
jQuery
between them:Unnecessary dependency "Do I really need
jQuery
?"Security, there are dozens of attacks using a fake
jQuery
Performance, while it is true that jQuery is fast, code forking and feature detection result in penalties, not to mention wrappers about DOM2 features, where the stack trace is broader
https://jsperf.com/jquery-vs-javascript-performance-comparison/22
Penalty in loading the page, if you use a stable and small version as it is
jQuery 1.7
, its minified version weighs only as1Kib
much as ! super mario bros weighed only ! 3 times less than ... those still need to be parsed and interpreted, resulting in a lag in page loadjQuery 3.0
87Kib
31Kib
jQuery 3.0
87Kib
Extra Data Consumption (only for mobile devices) Mobile phones generally use
planes de datos
those offered by telephone service companies, theseplanes
have a service charge , so when your page loads itjQuery 3.0
is unnecessarily spending these resources, if the user uses a browser without a system ofcaché
(absurd today, but imagine that there is one), for each page of your website, you would be spending87Kib
, that is to say that if your user enters and leaves the page a few1024
times he will have consumed87 Mib
only loadingjQuery
...extra learning curve
Sugary syntax, the sugary syntax of
jQuery
with$(TODO)
worsens the readability of the code, not to mention the absurd and excessive use of anonymous functions for everything.In general, it's best NOT to use jQuery, and if you do use it, it's best to just extract the necessary modules
To complete the previous answers, I must add that today (April 2018), the popularity of other frameworks such as Angular, React, Vue... and tools such as Typescript, WebPack and Babel.js has meant that we do not need to access to the DOM in the classic way or that we don't have to worry about incompatibilities between different browsers and the W3C standard.
In fact, mixing Angular or React with jQuery is completely counterproductive because component lifecycles are handled in a very different way by these frameworks and the potential interference of jQuery only makes life difficult for any developer.
jQuery has gone from being THE library to being one more option in a world that is evolving at an enormous speed.