Hey there DEV.to community!
Once I published a post about that I don't know jQuery anymore which you can check post here:
I don't need jQuery anymore, so don't you perhaps!
Adnan Babakan (he/him) γ» Nov 14 '19
Here I will tell you my explanation of why jQuery is dying and maybe is dead already. And some of jQuery's history.
What is jQuery and how did it become so popular?
jQuery is a free open-source JavaScript library used for designing the web and it was the most popular library back in its days. No one would imagine a web page without jQuery! It was first released on August 26, 2006, which makes jQuery a 13-year-old library thus a mature one.
Using jQuery you can write less code and do more (it is their slogan). Have the example below:
Vanilla JavaScript:
<button id="myButton">Click por favor!</button>
<script>
function buttonEventHandler() {
alert('Say Hi to VanillaJS!')
}
document.getElementById('myButton').addEventListener('click', buttonEventHandler)
document.getElementById('myButton').addEventListener('dblclick', buttonEventHandler)
</script>
Now have it in jQuery:
<button id="myButton">Click por favor!</button>
<script>
$('#myButton').click('click dbclick', function() {
alert('Here we go with jQuery!')
})
</script>
Cool, right?
This why people loved jQuery, it got them out of the torture sometimes JavaScript might put people in back then.
You can check more samples about jQuery and Vanilla JS in my post linked above.
JavaScript is killing jQuery
It is pretty hard to believe to destroy what you've made yourself but it is real. JavaScript is the language jQuery is written in but on the other hand, JavaScript eventually began to grow and adapt more features that people started to feel less needing jQuery. For instance fetch
API which took over XMLHttpRequest
and made it really easy to make AJAX calls and so many more examples.
So when you have something already built-in why would you add some more weight to your webpage? So there was a performance issue. jQuery eventually became heavier and heavier since they were adding new APIs.
No clean architecture
As for myself, I always felt pretty bad about how I'm writing jQuery and I've some other programmers about it and they were surprised about our mutual feeling. Some might say it is a programmer's fault if they are not writing clean code but I say it is a libraries design pattern fault as well. jQuery had no clean architecture and let you write your script as you like which sometimes caused bad practice code.
Rise of new JavaScript libraries/frameworks
The rise of new JavaScript libraries/frameworks such as Vue, React, and Angular was a big bang for the universe of web development. They made things much easier to do which jQuery couldn't accomplish by then. They also partially solved the architecture problem, they provided a way to write cleaner code, you can write bad code using them though but at least it is much less probable.
Single-page apps
SPAs (or Single Page Apps) are a relatively new way of designing web apps which is not possible by using jQuery so more and more websites had to drop jQuery when they switched to SPA technology.
SPAs needed a data layer to bind some data and change them consecutively which was not possible with jQuery or would require a lot more work to do, to be more precise.
CSS is becoming more powerful
This might be the most irrelevant one you'd think but I think it impacts the way jQuery is heading now. jQuery used to be a popular tool to animate web page elements which wouldn't be possible with CSS. CSS is now becoming more powerful and you can implement many animations using plain CSS without the need for jQuery.
One of the most common things programmers used to do was use jQuery to calculate some layouts' sizes, CSS now supports the calc
function which does almost 90% of the job needed.
I've seen some programmers using jQuery as their CSS variable holder so they can change the colors of a web page based on a value in their JavaScript, but CSS nowadays supports variables and is very convenient to use.
Is jQuery currently demanded?
Yes and no! If you are starting a new project or getting hired for a new one the chance of needing jQuery is less than 10%, but you better keep in mind that lots of websites that are built on some legacy code might still need jQuery since converting them would be a real pain.
These were my reasons why jQuery lost its popularity or as they say it died.
Tell me your opinion about this matter in the comments section below!
I hope you enjoyed it!
Top comments (1)
If you find yourself writing helper functions to simplify stuff, then jquery (or smaller clones of it like: github.com/fabiospampinato/cash) are a valid option - your first example shows how much less you have to write.
And as you pointed out yourself, jquery is still used in millions of legacy websites that aren't going to be refactored or rewritten in a "modern framework" any time soon, if ever.
I rather work on a site with jquery, than some early Angular 1 monster (which was a modern framework once) - use the tools that help archive your goals. Cheers.