jQuery vs DOM methods + es6

Hi. I have a question about jquery. Should I use jquery and what is best in terms of performance and good practice, to use jquery or to use pure DOM methods like getElementById and so on + combining it with es6?

I used to use jquery but now I see that it can be done without it, by my knowledge is limited so I just ask what is best from your perspective? Thanks

Your own projects? If you can do it with vanilla JS, do that. If you are looking to get a job where you might be maintained a legacy code base, do both, that’s like being able to speak Spanish and French: Gives you more options.

but if you would have a choice? I mean what is better, because I can’t understand if the difference is just in code or also in perfomance

jQuery has some overhead associated with it’s selector syntax. It is a fairly large library with many methods you may not use, so there is that extra bloat factor to consider. If you are going to be using many features it has to offer, then jQuery is still fine in my opinion, but pure JavaScript will typically run faster (assuming you have written efficient code) for certain tasks.

Well, if the world of the web, there is such a thing as a “minified” file, where whitespace is removed, and often, variable and function names are mapped to one-character names. This is because of the number of bytes that need to be transferred over the network. If you can do what you need without include all of jQuery (256kB or 85kB if minified), you will save two pieces of time (1: The request time, 2: the data transfer time). Every library you add (bootstrap, etc) adds to that time. The exchange for performance is ease of development, however: If you are learning, Javascript will likely be around for a while. The library-du-jour will not be, nor is there a guarantee that the one you learn will be what is being hired. React is the big thing now, but understanding how to “speak” different frameworks will be the most useful skill. Which is why I recommend both for someone looking to get hired.

Thank you both for explanations :slight_smile: