DEV Community

Cover image for Hating jQuery will not make you cool
Nitish Kumar Singh
Nitish Kumar Singh

Posted on

Hating jQuery will not make you cool

Hating jQuery will not make you cool; However, adoring it will also not make you cool.

But In 2019 adoring jQuery will make you dumb.

So,

Leave the jQuery as it is and continue your life without it.

Top comments (10)

Collapse
 
tobiassn profile image
Tobias SN

Actually some people still prefer to just use Vanilla JS + jQuery because they feel they don’t need a big library like Vue or React. And no, that doesn’t make them dumb, it just means they’re good at not depending on a single library.

Collapse
 
nitishk72 profile image
Nitish Kumar Singh

There was a time when I used to use jQuery of selecting element because that makes my life easy but Now we can do the same with Vanilla JavaScript also.

Collapse
 
tobiassn profile image
Tobias SN

Maybe, but jQuery still allows people to write code that’s smaller and sometimes simpler than when using Vanilla JS, and some prefer that.

Thread Thread
 
nitishk72 profile image
Nitish Kumar Singh

I completely agree with you that people use it and it is simpler. jQuery take around 30kb and beginners most of the time don't care about this cost.

People usually use 5-10 features and ships complete jQuery which is very bad.

Thread Thread
 
tobiassn profile image
Tobias SN

Actually 5-10 features in 30 kB is not bad at all.

Thread Thread
 
nitishk72 profile image
Nitish Kumar Singh

how?

When you can do the same with Vanilla JavaScript by writing little more code.

In 2019 you need not to write very much code compared to jQuery.

Thread Thread
 
tobiassn profile image
Tobias SN

Here's an AJAX call in jQuery:

$.ajax({
    url: "/faq/ajax",
    datatype: 'json',
    type: "POST",
    data: {search:'banana'},
    success: (r) => {
        console.log(r['name']);
    }
});

And it's Vanilla JS equivalent:

var r = new XMLHttpRequest();
r.open("POST", "/faq/ajax", true);
r.onreadystatechange = () => {
    if (r.readyState != 4 || r.status != 200) {
        return;
    }
    var a = JSON.parse(r.responseText);
    console.log(a.name);
};
r.send("search=banana");

To me, the jQuery version is clearly simpler and easier to read, with much less boilerplate.

And remember that the Fetch API still isn't fully supported on some browsers, so some people will still prefer AJAX.

Thread Thread
 
nitishk72 profile image
Nitish Kumar Singh • Edited

Yes, Vanilla JavaScript code is pretty ugly and I completely agree with that but using library just because your code doesn't look pretty is not a good idea at all. It will cost you a lot ( 30 kb).

Remember You can make the code more readable just by breaking it into function.

function ajaxRequest(url, params, callback){
    var request = new XMLHttpRequest();
    request.onreadystatechange = function()
    {
        if (request.readyState == 4 && request.status == 200)
        {
            callback(request.responseText); 
        }
    }; 
    request.open('GET', url);
    request.send();

}
    ajaxRequest('https://www.domain.com', null,function(response){
       console.log(response);
    }); 


Thread Thread
 
tobiassn profile image
Tobias SN

That was just an example. There could be a bunch of these cases in the code, and besides, 30 kB isn’t all that much anyway.

Collapse
 
nitishk72 profile image
Nitish Kumar Singh • Edited

I completely agree with you but this is 2019. So things are very much changed, Now Vanilla JavaScript is also very much powerful. You need not to depend on jQuery of basic stuffs.

In term of size React( React + React DOM ) and jQuery 3 are almost same.