jQuery is still "necessary"?

Asked

Viewed 812 times

8

I have recently wondered about the real need to still use jQuery in new web projects. I know that he was, until recently, the best means (and for many cases the only one) of manipulating HTML elements and making Web requests without worrying about the differences between browsers and without having to write thousands of lines of code to perform simple tasks.

The following features are easily accessed today with native Javascript from browsers:

inserir a descrição da imagem aqui

I got the idea of the functionalities from here.

I know that jQuery’s syntax is most often clearer and more compact. But the question is: jQuery is still "required"?

Note: I put the necessary in quotes, because I know there is no need in the strict sense of the word.

  • 6

    jQuery is not and never was necessary. It has never gone from a convenience.

  • I changed the title and put the necessary in quotation marks. I know it was never necessary, but I have the impression that nowadays it is much easier to disregard it in new implementations. I was hoping to find arguments to the contrary...

  • I’m reopening the question by understanding that the question is about compatibility between modern browsers.

  • Therefore and to achieve technical arguments, not based on opinion, to adopt jQuery in new projects.

  • As for IE, classList only works on IE10 onwards and partially! http://caniuse.com/#feat=classlist If you care about older browsers, jQuery is great for taking care of crossbrowser differences

  • Related http://answall.com/q/46983/101

Show 1 more comment

3 answers

4

"The following features are easily accessed today with native Javascript from browsers"

And always have been, how do you think jQuery was written? jQuery is Javascript, your use is just to shorten the code. Coming from this idea, jQuery grew and became what it is today, becoming one of the best Javascript libraries.

Is it necessary? This goes from opinion to opinion. I think it depends much design. If you want something with excellent speed, use Vanilla JS. Now if it’s something standard that doesn’t need anything extreme, why not use jQuery?

You’d rather use that instead?

$('.element').animate({
  top: 50px,
  left: 50px
});

Another example is the convenience of using $('elemento.classe') to take an element of the DOM instead of document.querySelectorAll("elemento.class").

  • The point is that browsers have evolved a lot from the time jQuery came into being to this day. jQuery is Javascript, but if today it is possible to write the same features without it (almost all) with the same amount of lines of code, why use it? Can’t make animations with CSS3 and even faster? What about the selector, if the $ is so important, what about: var $ = function (el) {
 return document.querySelectorAll(el);
}

  • 1

    @Marcusvinicius he did not refer to $, is an example, what he means is jQuery’s proposal: write less, in other words the idea of jQuery is you already have several things with few lines. If you are going to write an ajax application, you will have to write much more. Now if you want to add ajax in a function and the document.querySelectorAll in another, technically you started a library and you had to write it the same way :)

3

Why jQuery?

jQuery was launched in 2006, at a time when the most used Javascript Apis were not 100% compatible among browsers. This jQuery compatibility layer ended up with that 90% of the top 1,000,000 of websites in the world use this library. It’s a very expressive number.

jQuery usage data among the most visited sites in the world.

The big point of jQuery is not the compact syntax, but the compatibility between browsers. Doing a critical analysis, the syntax of jQuery is not at all clear: you can’t say what $("#abc") is making.

Pure Javascript

But Javascript has evolved, consolidated, and matured over the years. It has a specification (ECMA-262) well defined, and today, followed by the navigators. Before this was dream.

Today, making an HTTP request with pure Javascript is very simple:

var request = new XMLHttpRequest();
request.open('POST', '/my/url', true);
request.send(data);

Another facility of jQuery are the animations, however, in 2019, this is much better executed with CSS, by using GPU and not CPU for some things.

@keyframes fadeIn {
   0% {opacity: 0;}
   100% {opacity: 1;}
} 

And the compatibility problem between the browsers was solved both by the maturation of the language and the specifications, but also by the compilers, such as the Babel. It transforms:

[1, 2, 3].map((n) => n ** 2)

in

[1, 2, 3].map(function (n) {
  return Math.pow(n, 2);
});

jQuery is still needed?

In fact, jQuery was needed, such that 90% of the world’s top 1,000,000 sites used it. It was impossible to program for each Javascript engine of 2006. But today, there are better, more performative, and more elegant alternatives to solve the most critical problem: compatibility. Maybe you don’t need jQuery.

Verbosity is not necessarily bad. And simplicity is not necessarily good.

  • My question was indeed a provocation. Four years ago I didn’t see much feeling in using jQuery, but I wanted to raise this question because I saw many people still defending its use in 2015. Today it is still everywhere, but I don’t hear more about projects starting with jQuery.

  • I decided to answer her because today I saw the results of the Developer Survey 2019 Stack Overflow. It says 50% of developers use jQuery now in 2019.

1


It is necessary: NAY Jquery for the objectives pointed in the image is almost unnecessary (although I find it much better to use jquery to make AJAX requests) but* when you want to work with the graphical interface (make it look more beautiful, responsive) of your portal will be necessary to use some plugin or framework (if you do not want to do everything manually) they have as prerequisites the use of jquery. Some examples of frameworks you have with prerequisite jquery: JQuery UI, Twitter-Bootstrap and the Fondation.

*It is necessary the presence of Jquery but it is not mandatory the use of its functions, but as it is already present and as said in the question itself sintaxe do jQuery é na maioria das vezes, mais clara e compacta its use in this case is recommended.

  • Bootstrap is a really good argument to include jQuery. I have used a lot in my latest projects and help a lot.

  • @Marcusvinicius I can say that without Bootstrap (first UI framework) I would never be able to build a web project alone or with few financial resources.

  • I will mark your answer as accepted, since no one else interacted and you gave me a great argument to continue using jQuery: Bootstrap and other plugins that make life a lot easier for developers and designers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.