M
M
myskypesla2017-09-09 17:07:09
css
myskypesla, 2017-09-09 17:07:09

Which code in theory will work faster?

There is a big project with connected jQuery for plugins. But the rest of the JS if written without using jQuery, will it give at least some performance boost?
Option 1

var doc = document,
    link = doc.querySelector('.link');

link.addEventListener('click', function() {
  this.classList.add('active');
});

Option 2
var link = $('.link');

link.click(function() {
  $(this).addClass('active');
});

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Anton, 2019-05-22
@FreePunch

:before :after background with this image, the easiest option

D
D3lphi, 2017-09-09
@myskypesla

Will it give any performance boost?

By itself. Any library "drags" overhead. That's just the increase in speed in this example will not be noticeable.

A
Anton, 2017-09-09
@SPAHI4

In this example, there will be an increase in speed, but it will be so minimal that it can be neglected. And in real code, the performance will most likely be even worse, because. jquery has a bunch of optimizations. More effort will be spent, and the code will be more difficult to maintain in the future. So there is no point in saving on matches in this case, and taking care of performance in bottlenecks. For example, when animating, rendering large lists, updating, etc.

T
tema_sun, 2017-09-09
@tema_sun

Since jQuery already exists, why not use it? A handy thing. In your example, you won't notice the difference.
It may make sense to rewrite some separate pieces to vanilla js that slow down due to jquery. But this is not so common.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question