0

English is not my first language. I'm sorry..
I'm always trying to avoid using external modules like jQuery, Angular and so on.

In jQuery,

$('.desc').addClass('active');

This can be alternate like

function addClasses(className, class)
{
    cl = doc.getElementsByClassName(className);
    len=cl.length;
    for(var i=0;len<i;i++)
    {
        cl[i].classList.add(class);
    }
}

addClasses('desc', 'active');

It's more long but it behave same also We can save 85kb of jQuery Script file.

I think this approach is not bad and believe It could reduce more resource and increase performance. and It can apply directly if you share some codes in communities without installing external modules... add them to document... I hate those things really.

But I often use Codepen.io and even here stackoverflow communities, they all use jQuery or some external modules although it can be alternate a single line code.
Am i wrong? is jQuery and the other external modules does not effect on performances and resources thing? because actually, it's more easy to use and as a result, it makes more short script.

Oh Wan Sik
  • 53
  • 1
  • 7
  • 3
    This is very opinion-based, so it doesn't really belong here. Nevertheless, I'd say that plain JS is low-level and good for small applications and code snippets; but if you want to make bigger projects, you'll definitely need solid frameworks, with components, services, etc. like Angular or React. Otherwise you'll probably quickly end up with monstruous spaghetti code. jQuery IMO is just a pleasant little toolbox that avoids writing too much plain JS, but nothing more. – Jeremy Thille Feb 16 '18 at 07:51
  • Again, Sorry for my english skill I didn't really mean very opinion-based question but somehow it was.... I'm really sorry. But is writing too much with plain JS is worse? I didn't think about that. – Oh Wan Sik Feb 16 '18 at 08:05
  • Dude, relax. No need to apologize. Did you get any sanction? Nobody has voted to close your post or anything. You got some useful answers. So, this means it's not a bad question :) – Jeremy Thille Feb 16 '18 at 08:53
  • @JeremyThille actually.... I got some sanction recently. My poor english makes happen sometimes.. So I'm trying hard to not be rude or silly human and always be polite at all. but since I'm living asia not the european region or USA, I'm not sure what is polite really means and the amount of politeness in their country. – Oh Wan Sik Feb 16 '18 at 09:41

2 Answers2

1

jQuery is just a library, which contains very similar methods to the provided addClasses function. If you're a "Minimize killer", sure, you can create your own set of methods, only which you really need, or just use native Javascript without creating such methods (people leaved without jQuery somehow). But jQuery is not really heavy, I don't see much problems in using that.

Commercial Suicide
  • 13,616
  • 13
  • 48
  • 72
1

Everything depends on what you are building.

jQuery is actually a collection of useful shortcuts, just like you noticed. It's very appealing, mostly with younger developers, for its simplicity. But it has its flaws.

Angular (and React, AngularJS etc) are web application frameworks and go far further that jQuery. Using one of those will help you build an application with its own ecosystem. A framework is a design system, it gives you tools, but requires following their structure, schematics etc. For example, in both React and Angular, you have to build your views (html) inside the JavaScript code, which is then injected into the DOM.

Mecki gave a great response about the differences between a library (jQuery, Mootools, etc) and a framework (Angular, React, Ember).

The bottom line is, think what you are building. If something little, with very little logic, consider plain JavaScript. If you (or your team) prefer jQuery, try it, see if performance is acceptable. Actually, it's fairly easy to write JavaScript code that will be less performant that its jQuery equivalent. If something larger, try one of the front-end frameworks, like the ones I've mentioned. Just keep in mind that they have a steep learning curve. All the five-minute tutorials will show you the ropes, but venturing further will require a lot of work from you and your team.

And the last thing is, nowadays 85KB of JavaScript code is actually nothing, given browser caching and connections becoming faster every day. When your bundle will be +5MB, then you start to worry ;-)

Tomek Buszewski
  • 6,696
  • 8
  • 58
  • 103
  • Thanks about all articles. I'm making static work webs like network cloud service interface, I'm having already performances resources issues and I worried about little logics because it could became big logic because it can be looped a thousand times. but as you say so, I think I was too underrated those tools, because they are just tools, like hammer, screwdrivers you know, they all little heavy but it can do far more things though. – Oh Wan Sik Feb 16 '18 at 08:21