Live data from Hacker News

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

bennadel.com

1–10 of 55 posts

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

#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 parser, however it won't work with older browsers.

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

#6
So my project for this week has been removing jQuery from my app. I have to say it's been surprisingly easy. The only thing that's been annoying is that jQuery ignores the difference between querySelector and querySelectorAll, and just treats any operation done on a jQuery selection as if it were mapping a function to each item in a list. Which makes it super easy to write, but makes it much more difficult to know what's actually happening, and mildly annoying to then re-write.

That said, in addition to forcing me to restore a lot of fun animations that I had previously broken while porting the site from AngularJS to Angular, it also just ended up making the code a lot better. A lot of the times when we were doing something with jQuery, the same thing could have been done more cleanly using [ngClass] or whatever. So taking the three or four days to remove jQuery actually made the business logic of the site much easier to understand. Performance benefits aside, I'd definitely recommend it for this reason alone.

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

#7
post #4

I think zepto.js is a better choice. It's slightly bigger than cash but much closer to jquery (for example it has $.ajax) https://zeptojs.com

Cash's maintainer here. I don't think this is true actually.

Zepto supports some methods that Cash doesn't, but you probably shouldn't use them to begin with, like $.ajax, $.isArray, $.fn.animate etc. In 2022 either better built-in solutions exist or better specialized tiny libraries exist.

Everything that is supported by both Zepto and Cash should either work identically or Cash's implementation should be closer to jQuery's. Just to mention one thing in this regard you can run jQuery's test suite with Cash, and Cash's test suite with jQuery, easily [0]. I've done so and looked at every single failed test manually a few times, I doubt nearly the same level of attention went into Zepto. Just to mention one difference: Cash supports jQuery-style event namespacing, Zepto just doesn't support this, it is implementing something that looks similar but that works differently in pretty important aspects, that's worse than not supporting obsolete methods IMO, but I guess it depends on your use case for a library like this.

[0]: https://github.com/fabiospampinato/cash/blob/272132a6dc1d885...

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

#9
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…

The author mentions that enforces CORS restrictions which would break with their current server settings and CDN, otherwise I think they agree with you.

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

#10
post #9
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…

The author mentions that enforces CORS restrictions which would break with their current server settings and CDN, otherwise I think they agree with you.

Hmm, I think they should fix the CDN? I think if they just refer their script e.g. from https://www.jsdelivr.com/ it should just work? I have used bunch of modules from CDN.
Post reply on HN