jQuery was created in a far away 2006. At the time it was a huge time saver for many developers. Solving a lot of nasty crossbrowser issues, jQuery was a de-facto library in every new project.
Today browsers become smarter every day and the need of jQuery slowly fading. Many people tell it’s a good time to throw the library away claiming there is no place for jQuery in our modern world.
I think different and the article is about to tell you why.
I divide all the web page files in four categories:
A typical website or webapp scripts (logic) is the 3rd category files.
This means user will need it after getting all the html, css and maybe some pictures.
Let me explain it a bit: after getting the page user will spend some time watching your content (text, pictues) decising what to do, where to click or where to scroll. That means plus 187ms* of background work doesn’t make any sense.
And, yeah. You can’t promise your jQuery-less code will perform much faster 😉
As a bonus a GUI tool to create your own build of jQuery: http://projects.jga.me/jquery-builder/
And the last but not the least. Try to fix your main loading speed and performance issues before starting to blame jQuery. Have a look on Google Chrome Dev Tools metrics, discover your server ping, optimize images (and automate it), kill unnecessary libraries etc.
Many people say it’s a bad decision to start learning web development craft with jQuery. They say beginners would not understand the stuff deep enough.
My position is opposite.
I’m sure it’s a-w-e-s-o-m-e to reach cool results (well, any results!) fast at the beginning. It highly motivates you and gives a faith to complete learning.
Yes it’s possible to create all the things from scratch.
Simply don’t forget to:
Many of jQuery’s functionality has already been redone in http://youmightnotneedjquery.com offering sweet vanilla snippets.
transition: opacity 400ms;
But if you give it a tiny think you will notice than jQuery’s .fadeIn() is far more complicated and flexible:
Please don’t be blind and choose carefully.
One can’t do something like this:
let body = document.querySelector(‘body’);
// TypeError: body.classList.add(...) is undefined
Personally I adore jQuery for providing an ability to chain my code out of the box:
let form = $('#js-form'); //get the form
.removeClass('state-error') //remove red color
.addClass('state-success') //add green color
.find('.js-success-message-text') //get the success text
.fadeIn() //show the success text
.end() //get the form again
.find('.js-error-message-text') //get the error text
.fadeOut() //hide the error text
During the last 10 years jQuery community has grown really big. And so does the jQuery plugins list: https://plugins.jquery.com
You will find a huge collection of nice ready-to-use plugins there.
jQuery did an incredible epic work in the past.
Nevertheless, ol’ good jQuery is still usable and really helpful in some cases. It’s too early to bury the library.
* It will take about 47ms to download jQuery 2.1.1 (28.87KB gzipped) on average mobile networks (5Mbps) and 140 ms to initiate jQuery 2.1.1 on Chrome 50 LG Nexus 5.
Create your free account to unlock your custom reading experience.