Live data from Hacker News

Replacing jQuery (110kb) With UmbrellaJS (8kb)

bennadel.com

31–40 of 55 posts

Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)

#31
post #15

I generally replace jQuery with something like: $ = (s, p = document) => p.querySelector(s) $$ = (s, p = document) => p.querySelectorAll(s) If I’m feeling arrayish I’ll wrap the latter in [...qSA] so I can use .map and the rest of them, otherwise for/of works just as well. Anyone using $.animate() and $.ajax() this year should probably stop.

For some basic use cases that's probably good enough, but saying that that can replace jQuery is like saying that farts can replace rocket engines. For example I can do the following with jQuery: $(document).on ( 'click.ns', '.button', callback ); How should one do the same with vanilla JS? You'd end up rewriting a (probably buggy) reimplementation of jQuery's $.fn.on method in the end.

With the code here https://news.ycombinator.com/item?id=29979680 it would be on("click", ".button", callback). It doesn't take much to replace most uses of jQuery.

Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)

#32
Although this shouldn't detract from the author's specific situation and choice, I think a big share of those using jQuery are those who are also using a development framework that is dependent upon it ==> e.g., Twitter Bootstrap (ver 5 and below). That could be an interesting project -- a drop in replacement for TBS' jQuery dependency.

Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)

#34

I find it funny that I shared this article because I was proud that someone talked about my little library Umbrella JS, and so far 5 out of the 5 top-level comments are people recommending their/other libraries or ways of avoiding jQuery (and not 2 agree with the best way of avoiding jQuery!).

Take a look at most "show hn" posts, exactly the same issue. Looks like there is a group of people here that feel the need to self promote at any possible opportunity, from look at me I wrote this to look at me I also know about this. Quite sad.

Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)

#36
post #5

I prefer `querySelector` and bare ` ` tags for quick and dirty jQuery replacement. If you haven't keeping up with all the new script-tag parameters, I suggest looking at this: https://gist.github.com/jakub-g/385ee6b41085303a53ad92c7c8af... Choosing type=module is usually better choice than classic script tags like in the article. Module tags fetches (if any modules is used) asynchronously, and executes after the pars…

>Choosing type=module is usually better choice than classic script tags like in the article. Module tags fetches (if any modules is used) asynchronously, and executes after the parser, however it won't work with older browsers.

Also it provide some kind of JS hijack. All the code with in the module can be tainted by a random .js included elsewhere in the page. However code in module can still access the window object to have access to global and the dom.

Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)

#37

Earlier quoted context omitted.

For some basic use cases that's probably good enough, but saying that that can replace jQuery is like saying that farts can replace rocket engines. For example I can do the following with jQuery: $(document).on ( 'click.ns', '.button', callback ); How should one do the same with vanilla JS? You'd end up rewriting a (probably buggy) reimplementation of jQuery's $.fn.on method in the end.

With the code here https://news.ycombinator.com/item?id=29979680 it would be on("click", ".button", callback). It doesn't take much to replace most uses of jQuery.

Except that's broken beyond belief. Neither event delegation nor event namespacing are implemented in that snippet.

Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)

#38
post #22

Earlier quoted context omitted.

For some basic use cases that's probably good enough, but saying that that can replace jQuery is like saying that farts can replace rocket engines. For example I can do the following with jQuery: $(document).on ( 'click.ns', '.button', callback ); How should one do the same with vanilla JS? You'd end up rewriting a (probably buggy) reimplementation of jQuery's $.fn.on method in the end.

You use this library: https://www.npmjs.com/package/delegated-events

It doesn't support event namespacing.

Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)

#39
Almost all of these articles always have several caveats in place about features that aren't supported or libraries that are added to include missing features.

So its not really 'replacing' JQuery is it?

(no knock meant to @franciscop who didn't write the article or the title)

So I understand the desire to write your own libraries and use them. But isn't the author just replacing one third-party library with another? How is that really any better?

Aside from the size which really seems to be a bizarre thing to be commenting on. I've seen png files used for buttons that were larger than a compressed JQuery library

Post reply on HN