News for hackers. Stuff that matters.
Re:The Cost of JavaScript Frameworks by ng12 on Friday May 08, 2020 @02:09PM (#23117692)
Absolutely agreed. I have never in my life had a stakeholder get on my case because our site was 3mb when it could have been 1mb. I have had many stakeholders get on my case because we couldn't turn around features fast enough, or the site was buggy, or our UX was worse than our competitors. Those are the things that the people who pay me and my team care about and if I could 10x our bundle size for a 1.5x improvement in development speed I would do it in a heartbeat.
Re:The Cost of JavaScript Frameworks by untog on Friday May 08, 2020 @03:07PM (#23118258)
That depresses me because it's clear who is being ignored here: the user.

A 3MB bundle size instead of 1MB does make a difference, and if you're working on the kind of site that relies on conversions/purchases to succeed then you're absolutely leaving money on the table. Not to mention that Google factors in page load time to rankings.

> our UX was worse than our competitors

If your competitor has a < 1MB bundle and yours is 3MB then any user on a low end Android phone is absolutely going to have a worse UX experience. Maybe stakeholders aren't aware of all this. Maybe you should tell them.

Re:The Cost of JavaScript Frameworks by ng12 on Friday May 08, 2020 @03:37PM (#23118595)
Most of the apps I've worked on don't have conversions and aren't indexed by search engines. One app I worked on recently did have a mobile version that received a small fraction of all traffic, and even then overwhelmingly from relatively modern iOS devices.

It's like all engineering: use the right tools for the job. If low-end Android users are a significant portion of your target audience you have to design your system around that.

Re:The Cost of JavaScript Frameworks by tiborsaas on Friday May 08, 2020 @02:19PM (#23117800)
Dev experience and productivity is key, but don't forget that 10x bundle size has effects you can't simply dismiss. It does cause a UX problem since a slower pageload is part of the UX.

SEO. Google also takes into account page / paint times.

These are the things your stakeholders probably don't know about but you should.

Re:The Cost of JavaScript Frameworks by dirtnugget on Saturday May 09, 2020 @02:15AM (#23122706)
As a Frontend Engineer I can assure you there are ways to counter that issues but they're not exactly popular: Server Side Rendering. It adds another step t the build process in which HTML is prerendered, so you get the speed of loading plain HTML. It then loads the actual JS in the background. It's a PITA to implement
Re:The Cost of JavaScript Frameworks by tiborsaas on Saturday May 09, 2020 @04:45AM (#23123150)
With tools like Next.js or Gatsby it's not that bad. We use Next at work on a large scale and it works for us. But do you know what language gives you instant SSR? PHP :) It's funny how we had to invest so much effort to replicate with another language supports out of the box. I've built a blog in a few hours with Craft CMS, perfect tool for the job this case, I didn't even have to touch PHP files, just the templates.
Re:The Cost of JavaScript Frameworks by ng12 on Saturday May 09, 2020 @01:17AM (#23122503)
The majority of the projects I work on target users on desktops with modern browsers. You have to get into the massive 10mb range before noticing any lag, and even then only on an empty cache. SEO isn't a concern either, all of our marketing pages (when we have them) are static sites.

It's all about picking the right tools for the job. If low latency is a business requirement by all means don't use a framework.

Re:The Cost of JavaScript Frameworks by thinkloop on Friday May 08, 2020 @02:23PM (#23117846)
Wait another year or two and your stakeholders will smarten up - users are noticing. Svelte JS, for example, has everything you listed minus the costs. React is very far from the end of the road.
Re:The Cost of JavaScript Frameworks by ng12 on Friday May 08, 2020 @02:57PM (#23118159)
Maturity matters, unfortunately. I've been looking for a chance to try out Sapper but I wouldn't feel comfortable recommending that we start a major new project with it.
Re:The Cost of JavaScript Frameworks by aabbcc1241 on Friday May 08, 2020 @10:27PM (#23121679)
Also don't miss out S-js and Surplus.js. They are helpful tools to build reactive tools without VDOM.
[dead]
Re:The Cost of JavaScript Frameworks by hundchenkatze on Friday May 08, 2020 @05:23PM (#23119634)
For what it's worth I've been a native mobile dev for the past 10 years, barely touching any sort of web stuff (maybe updating my resume here and there). I was able to pick up Svelte very quickly, about 2-3 weeks tops.
Re:The Cost of JavaScript Frameworks by thinkloop on Friday May 08, 2020 @02:34PM (#23117941)
It's about a 4 hr learning curve from react - but I'm not shilling svelte, just showing that there are already superior models. Pre-compiling is really objectively better in every way except popularity, and that will change because of its betterness.
Re:The Cost of JavaScript Frameworks by ptx on Friday May 08, 2020 @03:54PM (#23118759)
What if you're compiling to JavaScript from another language, like e.g. Kotlin/JS? Does the Svelte compiler rely on some very particular JavaScript syntax, or could you run it on the JavaScript output from another compiler?
Re:The Cost of JavaScript Frameworks by lhorie on Friday May 08, 2020 @05:37PM (#23119776)
Svelte source code is not Javascript; it's a mix of JS, HTML, CSS and mustache-like syntax, so you wouldn't necessarily be able to compile to Svelte using out-of-box tooling from other ecosystems. I suppose you could compile to Svelte output, but then you'd just be reimplementing it in a different language.
Re:The Cost of JavaScript Frameworks by ptx on Friday May 08, 2020 @05:54PM (#23119954)
Ah, that's unfortunate. At least with React (and Mithril) you can use it from pure JavaScript, which lets you replace JSX with Kotlin's DSL[1] for HTML.

[1] https://github.com/Kotlin/kotlinx.html/blob/master/README.md

Re:The Cost of JavaScript Frameworks by yencabulator on Saturday May 09, 2020 @01:18PM (#23126524)
I find using HTML for HTML much more pleasant.
Re:The Cost of JavaScript Frameworks by ptx on Monday May 11, 2020 @06:35AM (#23140668)
I do too, for simple things. But what do you do when you have repeating patterns and want to eliminate duplication? Usually a template language would be introduced, and now it's not HTML anymore; tools that work on plain HTML don't work with the special template language; commenting out code gets tricky because the same file has multiple kinds of syntax intermixed. And in addition to your HTML and your template language you still have your programming language.

Kotlin solves this by using the programming language for the whole thing, allowing you to extract repeating parts using plain functions as you would with any other code. Of course it's not as well suited as HTML itself for writing HTML, but it might be better than HTML + some template language + some programming language.

Another way to go, to avoid having a mysterious mixture of almost-HTML embedded within some other syntax, is to do what Thymeleaf does[1] and have the template language be embedded inside HTML (rather than the other way around) so that the template file is actually valid HTML.

[1] https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.h...

Re:The Cost of JavaScript Frameworks by aardvark1 on Friday May 08, 2020 @02:39PM (#23117991)
Superior in what way? Do you really trust that SvelteJS is going to be a better product in 5 years over something like React that Facebook invests millions of dollars every year?
Re:The Cost of JavaScript Frameworks by dwoot on Friday May 08, 2020 @04:14PM (#23118938)
I don't think anyone is going to sell you on something else, you seem very ingrained in the React ecosystem. More dollars doesn't equate to "better product" down the road. Angular came and is still a part of Google. Would anyone starting a new project use it over something like VueJS or React today? Probably not. Right? So that sort of tosses your argument out the window.

I don't do JavaScript professionally anymore, but I've worked with jQuery, BackboneJS, lots of AngularJS, some Elm, some VueJS, and some React, but being the curious person that I am, in search of greener pastures, I checked out Svelte, by first watching Rich Harris' video https://www.youtube.com/watch?v=AdNJ3fydeao on "Thinking Reactivity", then seeing the benchmarks: https://twitter.com/Rich_Harris/status/1200807516529147904, and watching Rich and Dan Abramov spar a bit over their challenges. From an outsider with no skin in the JS game, it is clear that Svelte seems far superior now and into the future...

1. it is a compiler (it's like comparing C/C++ to Python) 2. the joy of out-of-the-box animations that use the GPU in CSS (reminds me of the joy of using jQuery for the first time w/ it's OOB animations) 3. you can drop in any other JS lib (doesn't have to be in a particular JS framework ecosystem) and have it inter-op! This is huge! It's because it's literally like writing vanilla JS 4. no need to learn some new syntax like JSX (not a huge fan)

Just take a peek. If you don't like Svelte, so be it, but at least you know what it is that you don't like rather than turning a blind eye because you don't want to be convinced -- that's tunnel vision.

I was trying to decide between React/Vue/Svelte for a project I started recently, and after having attempted to build to-do apps in each, I landed on Svelte.

Re:The Cost of JavaScript Frameworks by aardvark1 on Friday May 08, 2020 @05:01PM (#23119421)
I am not at all a React fanboy, I'm just using is a metaphor for Vue/Angular/React. You're selling Angular short it's still a great framework that is very popular, even better than React for some use cases as it has more out of the box and is more opinionated
Re:The Cost of JavaScript Frameworks by dwoot on Friday May 08, 2020 @11:57PM (#23122178)
Your actions say otherwise.

You want to turn this into a framework/lib debate? I'm checking out. Angular is popular in the same vein that PHP is popular. People still use it. In fact, CodeIgniter is still very popular. It certainly has some use cases that certainly beat things like Rails, too. I see where you're going with this -- you care about popularity. Got it. Well, Svelte will check out now.

I could care less for any framework. I'm looking for the least friction, highest expressiveness, maintainability, and last, but not least, portability.

I just left a company that did React having spent the last year ripping out Nuclear for Redux and now there are React Hooks and Contexts. Hire massive teams to spin wheels rather than feature development and chalk it all up to tech debt sounds like fun.

WhatsApp would not exist if people didn't use more obscure technologies. 50 person team on Erlang for nearly a billion-user product while some organizations want to run 500 person teams to refactor the code written only a year ago be it Java or JavaScript.

Re:The Cost of JavaScript Frameworks by thinkloop on Friday May 08, 2020 @02:56PM (#23118155)
A hello world react app with everything you would typically need (redux, router, etc.) starts at 100K+. Svelte is a couple K.

A react app has massive abstraction to render on every frame, Svelte compiles out the framework to render instant straight vanilla js (wins all perf tests).

Pre-compiling allows for beautiful syntax and more flexible app structure, since you aren't limited to the runtime.

SSR and code-splitting are significantly easier and more straightforward.

React is designed for a billion-user site and it shows.

There really is zero cost to pre-compiling except mind-share, and only benefits. Of course an F100 company has many concerns above tech awesomeness, so no judgement on your selection criteria. But I assure you this movement is coming, react/vue/angular will adapt/change and/or people will move to Svelte-like solutions.

You can already see it happening in the article facebook released today [1]:

"By using rems, we can respect user-specified defaults and are able to provide controls for customizing font size without requiring changes to the stylesheet. Designs, however, are usually created using CSS pixel values. Manually converting to rems adds engineering overhead and the potential for bugs, so we have our build tool do this conversion for us."

[1] https://news.ycombinator.com/item?id=23116300

Re:The Cost of JavaScript Frameworks by nicoburns on Friday May 08, 2020 @03:21PM (#23118407)
I'm not convinced that the 100kb is what's causing the perf problems though. It's not that hard to make a React app that loads almost instantly. There are lots of huge, slow react apps, but that's due to poor engineering choices not the framework.
Re:The Cost of JavaScript Frameworks by dwoot on Friday May 08, 2020 @04:21PM (#23118998)
You have not looked at Svelte. You've still the overhead of a virtual DOM and its diffing. People that turn a blind eye to Svelte will be blind-sided. It's like writing vanilla JS without all the baggage, because it's a compiler (think C++ versus Python).

I highly doubt that one can build a ReactJS app that loads faster than a Svelte one. I encourage you to try and share it. This is coming from someone that is a backend engineer that doesn't really do JS, but have had to for my own personal project and both perf and the subjective bit of expressiveness and joy of writing are important. Contrary to popular belief, people think that Svelte is trading perf for ugliness and lack of expressiveness.

Re:The Cost of JavaScript Frameworks by nicoburns on Saturday May 09, 2020 @10:53AM (#23125143)
So I had (an admittedly brief) look into Svelte on the back of your comment. And one thing that stands out to me is that it appears to be using string templating. This isn't a complete dealbreaker, but it's definitely a step back from the React world where everything is JavaScript. This was by far the biggest pain point in other frameworks like Angular, so I'd be pretty reluctant to go back to it.

Looking at the framework benchmarks (https://krausest.github.io/js-framework-benchmark/current.ht...), svelte is indeed a good bit faster than React. However, Inferno which takes a react-like virtual DOM approach but better optimised is faster still. So I'd be more inclined to go with that if I were willing to give up the React library ecosystem.

Re:The Cost of JavaScript Frameworks by uhoh-itsmaciek on Saturday May 09, 2020 @02:56AM (#23122832)
I see TypeScript support is on the road map. I haven't used it yet, but that's exciting.
Re:The Cost of JavaScript Frameworks by postalrat on Friday May 08, 2020 @11:23PM (#23121986)
I love react. But when I hear developers say their react app loads instantly I think:

1) Their app is pretty small

2) Their machine is really fast

Re:The Cost of JavaScript Frameworks by lhorie on Friday May 08, 2020 @03:11PM (#23118306)
That may be the case for React, but the vast majority of your stack (e.g. react-router, react-redux, styled-components, etc) certainly don't have millions of dollars being poured into them. The base frameworks are very very similar in terms of what types of features they provide.
Re:The Cost of JavaScript Frameworks by aardvark1 on Friday May 08, 2020 @03:35PM (#23118559)
The author of redux works at Facebook
Re:The Cost of JavaScript Frameworks by acemarke on Friday May 08, 2020 @04:09PM (#23118905)
Both Dan Abramov and Andrew Clark (co-creators of Redux) were indeed hired by Facebook to work on the React core.

However, Dan and Andrew haven't actively touched Redux library code since mid-2016. (Dan occasionally drops into an issue to comment, like his suggestion to not ship a `useActions` hook for React-Redux, but that's it.

The _current_ maintainers (Tim Dorr and myself) do not work for Facebook, and Redux has never been a Facebook-sponsored project. We're an independent open source project.

We chat with the React team frequently via Github and Twitter and such, but that's just OSS collaboration work.

See https://blog.isquaredsoftware.com/2018/03/redux-not-dead-yet... for more details.

Re:The Cost of JavaScript Frameworks by lhorie on Friday May 08, 2020 @03:54PM (#23118761)
AFAIK gaeron hasn't touched redux stuff at all for a while, and acemarke/timdorr are not FB employees.

Also same ecosystem story there: redux-saga, redux-form, etc are all low/no budget projects.

Re:The Cost of JavaScript Frameworks by aabbcc1241 on Friday May 08, 2020 @10:23PM (#23121663)
And also server side rendered SPA (keeping the VDOM on the server)
Re:The Cost of JavaScript Frameworks by milesvp on Friday May 08, 2020 @04:01PM (#23118826)
I was lucky at one point to work with product owners who understood that latency translated to lost revenue and so they helped champion the idea that engineering excellence was actually valuable, and that squeezing out performance was itself a worthy goal. It helped that we could compare our metrics to comparable sites, and could give upper management bragging rights when our pages loaded faster than bigger higher staffed “competitors”.

But otherwise, I think you tend to be right, in a lot of areas even an extra second of latency doesn’t matter, and more features will move the needle more.

Re:The Cost of JavaScript Frameworks by goatlover on Friday May 08, 2020 @02:24PM (#23117855)
2 more MBs is going to matter to some users with limited data or bandwith.
Re:The Cost of JavaScript Frameworks by ng12 on Friday May 08, 2020 @02:53PM (#23118120)
Sure, that's a trade-off you have to make a decision on when designing the core architecture. If your users are sitting behind corporate T1 connections near an AWS data center bundle size doesn't matter at all. If your users are still on 3G phones it matters a ton. For somewhere in between it becomes a business decision: how much performance are you willing to trade for developer productivity?
Re:The Cost of JavaScript Frameworks by hundchenkatze on Friday May 08, 2020 @05:15PM (#23119560)
You're comparison implies that T1 is faster than 3G, but that's probably not the case except in really poor coverage areas.

T1's maximum data transmission rate is 1.544 megabits per second. [0] While 3G's theoretical maximum is 21.6 Mbit/s for HSPA+. [1]

[0] https://en.wikipedia.org/wiki/T-carrier#Transmission_System_...

[1] https://en.wikipedia.org/wiki/3G#Data_rates

Re:The Cost of JavaScript Frameworks by entha_saava on Saturday May 09, 2020 @12:14AM (#23122259)
In practice, 3G is quite slower than that.
Re:The Cost of JavaScript Frameworks by nojito on Friday May 08, 2020 @05:34PM (#23119760)
>I have never in my life had a stakeholder get on my case because our site was 3mb when it could have been 1mb.

As cloud costs become tougher to swallow, this is going to change.