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.
Replacing jQuery (110kb) With UmbrellaJS (8kb)
31–40 of 55 posts
Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)
#32Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)
#33Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)
#34I 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!).
Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)
#35Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)
#36I 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…
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)
#37Earlier 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.
Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)
#38Earlier 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
Re: Replacing jQuery (110kb) With UmbrellaJS (8kb)
#39So 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