Days are not jQuery

Before coming to the article, invite your aunts and grandmother to enjoy the masterpiece

As everyone knows, jQuery is a very popular javascript library, so popular that some of my friends used to write jQuery without knowing javascript.

It can be said that jQuery is like a psychological and perverted girl who needs to be there, go from A to Z too.

However, everything has two sides of it, the ones that we have not yet said at the end of the lesson. This article also does not aim to advise you to break up with the jQuery girl, but try a day away from her, how do you realize that celibacy is so wonderful.

Some no-jQuery examples

1. Listen to the event

Many developers have a habit of including all js by $ (document) .ready ():

And pure JavaScript can be as follows:

What about a click event? JQuery users will code as follows:

And when not using jQuery:

Not so bad.

2. Select the elements

To select elements, jQuery allows very short code:

With JavaScript it will be as long as a bit:

3. Use AJAX

Using jQuery is too quick:

And when not using jQuery:

4. Add class less

jQuery provides two methods to add class (addClass), less class (removeClass) and because it is very spoiled, the bonus adds an island (toogleClass):

We have to do quite a lot with pure JavaScript:

5. fadeIn effect

This is one of the secrets that users have just met has exploded the disk, especially the brothers of silk, like new and sparkling:

Only a short line of code is enough to satisfy the "legitimate needs" of the zai.

If you take a selfie at home with JavaScript, this is it:

Also happy as losing time even more.

6. Hide current element

With jQuery:

No jQuery:

7. Control DOM

Try with inserting the card

into the #container element:

JavaScript is not too cool:

Delicious but it's "easy", is there a problem?

There is …

1. Influence the perception

As I mentioned at the beginning of the article, I know quite a lot of people who use jQuery but don't know JavaScript. What happen?

A correct sequence will be: JavaScript> Web API> jQuery.

But many people immediately contact jQuery and do not understand the nature of the problems behind it. This is not good for professional development.

Please note this issue.

2. Must import the library

You can't just get a jQuery part for what you need. You must import the entire library with a minimum size of approximately 300KB or use a minified library that is about 30KB in size.

Do you think this is a big problem? Imagine, in a beautiful day your website received 1 million requests, the amount of jQuery downloads would be equivalent to 30GB

That's not to mention you can use dozens of additional plugins.

You can replace it with using CDN, but that only reduces the server load, not faster page loading speed.

Having a card is not a big problem. Please continue with the following issues.

3. Processing speed

In essence, jQuery writes functions that handle shells outside JavaScript to be more user-friendly, which of course will make processing speed slower. Try some tests to see how slow it is:

=> It's nearly 50 times slower, it's worth thinking about.

In addition, there is a website to help you find alternative jQuery codes. If needed you can access: youmightnotneedjquery.com .

I reaffirm that this article is not intended to advise you to abandon jQuery, nor to deny the excellence of jQuery. Simply add a little more information to make your choice more accurate.

Happy coding!

ITZone via kipalog

Share the news now