HTML + JQuery, which the hydration approach is compared with, is not used for performance reasons per se. It's used because its easier to reason about and the incremental interactivity that something like JQuery brings to HTML is better than writing your entire frontend in React for something as simple as a blog, for example.
FWIW, the linked site is built with a 300 line custom build script, Rollup, Buble & Terser - even the dev dependencies are extremely minimal. no, it doesnt have the latest HMR hotness, so the DX could be a bit better if i wanted more bloat.
it's like 1/10th the size, api-compatible and well-architectured.
Out of curiosity, what do you think of Alpine.js and Stimulus.js, which come to mind when I think of smaller utility libraries for adding "sprinkles" of JS?
no experience with those, but if you're feeling masochistic, try these:
Without bubbling event handling, it's a no go for handling event on dynamically generated inner content.
https://developer.mozilla.org/en-US/docs/Web/API/Element/mat...
* in limited cases like tabular data or large lists
https://us.thermosoft.com/floor-heating/systems/thermotile-m...
* Edit -- initially i incorrectly claimed that this site uses mithril -- (it uses domvm w/SSR, not Mithril)
the link above disables Google Analytics on that page, which would otherwise add an extra 50ms of js time (and would account for the majority of the js on the page).
(it uses domvm w/SSR, not Mithril)
To me, it seems like Incremental Static Regeneration is the best of both worlds - you get a static site without huge build overhead and SSR niceness.
However, peeking in dev tools, sure enough your site is a bit faster in nearly every lighthouse metric compared to static-tweet.now.sh despite being decidedly more complex.
Could you expand on how Gatsby and Next are doing SSR wrong and what it takes to do it right (i.e. what is DOMVM doing instead).
I'm sorry if you've answered this elsewhere in the thread, I looked around and didn't find anything.
please read through the whole Reddit thread i linked. i compare a minimal Next.js hello-world page to domvm-rendered e-commerce page. what specifically they do to produce such a sub-optimal result will remain a mystery to me because i don't particularly care to investigate. no one has given me a bare-minimum Gatsby site to evaluate so i have no idea how it compares besides looking at one of their slow showcased apps in the reddit thread: https://airbnb.io/
i think a lot of your questions may be answered by reading the Reddit thread.
> SSR can be done correctly, even with React
This stands out to me, and I agree completely.
I dug around in devtools and found a few interesting things looking at the static-tweet.now.sh (Next w/ Incremental Static Regeneration). It seems like the performance is more or less on par with domvm as far as network usage EXCEPT for the initial bundle (which is mostly react & dependencies). For subsequent visits, this is cached and performance is great, but devtools tests with a clean cache so this is hidden.
Admittedly, that's a huge qualifier. It doesn't seem like Next is doing anything wrong with SSR other than using a framework with a huge bundle. As a result, the huge bundle ends up getting sent even for a page (or entire site) with no interactivity.
In theory, it might be possible to avoid sending the bundle for routes that don't need it, but this ends up being a fundamental limitation of react afaik.
Vercel (the folks behind Next) put it really well
> React at Facebook is… > …unlike React at ${anywhereElse}
The large initial bundle pays off for a site like facebook or a web app which really takes advantage of all React has to offer (wether that's performance, tooling, or dx), but definitely deserves more second guessing than it recieves.
perhaps it's possible with Preact|Inferno + SSR, i dunno. but this [1] seems to use babel/webpack and a bunch of other stuff. it's not clear to me from that post how minimal the end result can actually be.
the thing is, React's ecosystem is also to blame, it is so full of ready-to-go-do-everything popular components with inefficient code that cannot be tree-shaken, that lack of care in bundle evaluation is absolutely rampant. every imaginable feature is just some burned-out dev's `npm i` away, node_modules be damned.
[1] https://www.digitalocean.com/community/tutorials/build-a-ssr...
if you add to the cart and reload the page, it pulls the live cart from the db.
Just a heads up, there is a NaN showing at the end of the page.
that "Chat Now" needs to be position: fixed, and styled, too. WIP!
of course, everything will feel snappy if you just defer it, but your battery does not feel the same way :D
The only thing I've found these metrics useful for are baselines for regressions over time.
> Do you actually go interview users on what they perceive?
Yes, regularly, because that's what effective teams do. I also limit bandwidth to 3G and record the sessions so that everyone can share in the learnings, which very rarely circle back to things like TTFB/TTI.
Time to fist byte? Last byte? First paint? Interactive? These are great, but do not always capture the entire picture of what's actually important - do your users perceive the experience as fast?
to quote Rick & Morty: "Must be nice!"
I have been doing the latter for some time with https://github.com/airbnb/hypernova for a rails API.
except it's not "here-and-there". everything down from `<html>` is re-SSR'd and fully re-hydrated on each page load.
here-and-there is what jquery does.
I ask because my server app is not a nodejs process and don't want to add one for now but do want to avoid heavy state management and client side routing as you did.
https://krausest.github.io/js-framework-benchmark/current.ht...
but re-hydration is much faster than actually building the dom from scratch in js. instead of 20ms, it might be 60ms + some extra for render/layout time.
however, unless you have very DOM-heavy pages, the perf should still be great from a user's perspective. you may get some flashing between page navigation since when you build the DOM in JS with domvm it's not streamed, but when the browser is parsing server-sent html, it is. the only way to know is to try it for your specific case.
if you need SEO, it's probably sub-optimal and may take longer to for Google & Bing to index, from everything i've read.
So I loaded up this Next hello world: https://hello-world-app-eight.now.sh/
I can see it downloaded 65kB of compressed JavaScript which is _a lot_.
I worked on a small Mithril SPA and the compressed JS bundle (which includes the CSS) is 41kB. Granted it's not a complex app, but it's certainly not a hello world.
It’s not like the 65kb here is 1kb for every N characters of text. It’s an overly simplified “hello world” example. The point is that you’ll still see sizes of around 65kb even with much more complexity than “hello world.”
One takeaway was that given a large sample of sites, the baseline size correlates fairly well with how the bundle size scales as projects grow. So if you have a 65kb baseline, you're more likely to end up with a larger bundle size in a "real world" project than if you used a framework with a 5kb baseline. The reasons are not clear (they could be anywhere from direct causation to indirect causes like incidental complexity due to some communities' higher likelihood of using libraries without auditing them), but the results are what they are, nonetheless.
Also, 65kb gzipped means you're running the uncompressed amount of JS. As a rule of thumb, the more JS you're running, the slower the site is going to be. This matters a lot for mobile, where JS execution speed can be absolutely abysmal (on top of slow network speeds, higher chance of resource timeouts, etc).
[1] https://timkadlec.com/remembers/2020-04-21-the-cost-of-javas...
It's also 65kB of compressed and minified JS which ends up being about 185kB for doing absolutely _nothing_.
For comparison the complete jQuery library weights about 30kB compressed and minified.
https://old.reddit.com/r/javascript/comments/ghfyd2/secondgu...
specifically this sub-thread of Mithril's author and myself doing a "Hello World" Next.js perf assessment vs a full-blown ecommerce page:
https://old.reddit.com/r/javascript/comments/ghfyd2/secondgu...