News for hackers. Stuff that matters.
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by throwawaysky9 on Sunday August 19, 2018 @11:05AM (#17794546)
I don't want to be "that guy", but haven't most people moved on to something like Vue instead of manipulating the DOM directly? Every developer I've worked with learned the basics of Vue quickly (less than a day) and marveled at how great it was compared to manipulating the DOM through jQuery (or something similar like Umbrella JS). But sure, there are edge cases where jQuery and similar libs still serve a purpose.
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by simonw on Sunday August 19, 2018 @11:09AM (#17794556)
Vue and React make sense for large SPA-style applications, but I often find myself wanting to drop a few lines of JavaScript onto a page to implement something simple without pulling in a massive framework dependency that requires a webpack compile step.
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by EB66 on Sunday August 19, 2018 @04:46PM (#17796092)
> Vue and React make sense for large SPA-style applications

Agreed, but I want to point out that modern, large SPA-style app architecture and jQuery are not necessarily mutually exclusive. jQuery might not work with React and Vue, but it can work alongside other frameworks just fine (yep, without manual DOM manipulations).

jQuery offers utility beyond ensuring your code runs the same across different browsers. For instance, I've yet to see another `replaceWith` as concise as what jQuery offers or DocumentFragment generation as expressive as this: `$("<div>hello world <span>foo bar</span></div>");` For those two examples, the alternatives listed on http://youmightnotneedjquery.com/ are either very verbose or do not mimic the full functionality offered by jQuery.

Where I work we've built an in-house JS framework inspired by React and Vue but that "plays nicely" with our jQuery legacy codebase. The framework evens uses jQuery at it's core for UI state management and DocumentFragment generation. Re-factoring our jQuery legacy code is a breeze when compared with re-writing it to conform to React or Vue standards. We write modular and consistent components with `this.props`-style state management, one-way data binding, and zero manual DOM manipulations while still using jQuery.

TLDR: jQuery offers utility beyond manual DOM manipulations and smoothing out browser differences. When used appropriately, it still has a place in modern JS component architecture.

Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by mmargerum on Sunday August 19, 2018 @11:18AM (#17794589)
You don’t have to use webpack with vue. Only if you want single file components. You literally just include in script line and you can use vue. No harder than jquery.
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by throwawaysky9 on Sunday August 19, 2018 @11:22AM (#17794611)
jQuery is 84 KB minimized, while Vue is 85 KB. Not much of a difference (although, granted, Umbrella JS is notably smaller). You don't necessarily need Webpack for Vue, you can just include Vue in a script tag and write your code.
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by wild_preference on Sunday August 19, 2018 @01:35PM (#17795263)
But it’s also about abstraction overhead. You wouldn’t bring in Vue to add a Select All button that checks a bunch of checkboxes.

You wouldn’t use jQuery/Umbrella for that either, but there might then exist a middleground where you would. e.g. any time you’re adding JS to an existing page but don’t want a whole component abstraction.

Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by gremlinsinc on Sunday August 19, 2018 @06:26PM (#17796522)
You might use VUE for that if you need it to work across pages/tabs and use a state/store like vuex to maintain the state of the checkboxes....or the react equivs...I mean you can use localStorage..but I prefer vuex.
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by pier25 on Sunday August 19, 2018 @08:53PM (#17797065)
Neither Vue nor React are really frameworks, and both can be used with a script tag without a compile step.
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by gremlinsinc on Sunday August 19, 2018 @06:24PM (#17796516)
Vue is VERY much an easy drop in for small things..I've totally started replacing it wherever I'd otherwise have used jquery... and I can't say I'm sorry I have. But all my projects use laravel on backend, and laravel has webpack/vue baked in so there's really nothing I need to configure for it to work, too much..a little tweaking in the app.js file..that's all.
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by franciscop on Sunday August 19, 2018 @11:41AM (#17794680)
For the other points, the other comments are quite spot on.

Load speed:

Umbrella's 2.5kb loads well under the rule-of-thumb size of a single packet of 14kb [1], so you have to do a single roundtrip for that [2]. In this 3rd party test [3] it takes ~200ms to load the whole Umbrella JS. JQuery weights ~30x more kb, so there are several packets sent, which makes it load in ~2s in the same test.

Not to mention parsing and running all that extra JS.

Heck, I regularly bundle my whole JS in a single file and thanks to Umbrella JS tiny size the whole thing weights well under 14kb. It loads in a snap.

Edit: early send

[1] https://tylercipriani.com/blog/2016/09/25/the-14kb-in-the-tc...

[2] Excluding the TLS trip, which is common anyway.

[3] https://speakerdeck.com/mattclaffey/using-umbrella-js-for-mo...

Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by waveforms on Sunday August 19, 2018 @11:26AM (#17794624)
According to this website [1] jQuery is still used by over 70% of websites. I have built production sites in extjs, Dojo, Angular, React etc. but nothing beats the fun of throwing up a quick website in jQuery and Bootstrap. Its even more fun with es6 now! I am looking forward to where jQuery and other DOM manipulation libraries go in the future. [1] https://w3techs.com/technologies/details/js-jquery/all/all
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by Secretmapper on Sunday August 19, 2018 @11:34AM (#17794654)
Spot on! I'm a ReactJS developer by trade, but when doing side projects, I still use jQuery from time to time, especially if the client is not that state-heavy. I know I can make do with fetch, querySelector/All and the like, but I'd rather take the convenience.

Related: https://robots.thoughtbot.com/how-we-replaced-react-with-pho...

Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by franciscop on Sunday August 19, 2018 @11:40AM (#17794676)
Yep, exactly. I use Umbrella JS (author here!) for most side projects. I only reach for React for SPA and state-heavy projects. These cases with jQuery (or Umbrella JS) is tricky because while you can do it with template strings, you don't get the modularity, build tools and it's difficult to protect against XSS.

You have to be very, very careful with .html(...) and only for that reason sometimes React is worth it, specially with SPA. But for small-to-mid sizes projects, Umbrella JS FTW!

Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by krishanath on Sunday August 19, 2018 @11:57AM (#17794754)
There are tiny alternatives to React that support JSX syntax. This library is better when you want to be "closer to the metal": https://github.com/wisercoder/uibuilder
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by ttty on Sunday August 19, 2018 @01:45PM (#17795318)
It's interesting, I couldn't write jquery website anymore, even if simple, they become more complex so quickly. Add this feature...

Sidenote: Anyway in my brain jquery/templates never made sense. I always wanted components, pass some arguments and get the component, self contained.

Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by alangpierce on Sunday August 19, 2018 @01:16PM (#17795161)
Just to balance the "70% of websites" number, I've worked on a number of websites where there was still some legacy jQuery floating around, but where all new development is expected to happen in a modern framework like React, and new code using jQuery would be unlikely to pass code review. Or, perhaps, where jQuery is legitimately used as part of the occasional escape hatch when you can't use React for some technical reason, but is discouraged and only used with careful scrutiny.

I suspect that if you refined it to "How many new websites in the last year use jQuery as their primary UI library?", the number would be much lower.

Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by the_duke on Sunday August 19, 2018 @01:42PM (#17795300)
But why do you need jQuery for that? Browser APIs have gotten good enough that jQuery is not really needed anymore, imo.
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by CM30 on Sunday August 19, 2018 @11:18AM (#17794591)
Not all of them. There are still plenty of sites that aren't SPAs, especially those built with CMS' like WordPress, Drupal and Joomla (or various forums, wikis, etc). In those cases, you don't want to have to redo the whole frontend in React or Vue, you just wanta simple way to manipulate DOM elements for things like a dropdown menu or modal or what not.

Something like this may work fine for that purpose. There are still thousands or millions of websites that don't act like an SPA/

Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by goatlover on Sunday August 19, 2018 @11:37AM (#17794663)
> There are still plenty of sites that aren't SPAs, especially those built with CMS' like WordPress, Drupal and Joomla (or various forums, wikis, etc)

It's as if those sites don't exist for the HN crowd, even though they make up the majority of the web.

Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by Sharlin on Sunday August 19, 2018 @06:16PM (#17796480)
Ironically, of course, HN itself is one of them.
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by ivanhoe on Sunday August 19, 2018 @02:48PM (#17795615)
it's definitely less used nowadays, partially because vue/react take care about a lot of work themselves, but also partially because virtual DOMs and component scopes make it complicated to work with DOM directly. I often run into little eye-candy things that jQ could take care of efficiently in a few lines of code, but because of everything else you end up building Animation components and HOCs instead that are in the end much more complex...
Re:Show HN: Umbrella JS, a 2.5kb jQuery alternative by jedisct1 on Sunday August 19, 2018 @01:38PM (#17795275)
Wordpress.

Other than that, I don't see any reason to use jQuery (or something similar) in 2018.