4 ms·
In Javascript SSR, if you need the same logic on the client and server, define an API module + interface. Make a different API bundle on the server that calls N
by stevebmark 4y ago
In Javascript SSR, if you need the same logic on the client and server, define an API module + interface. Make a different API bundle on the server that calls NodeJS functions, file reads, whatever, directly. Make an API bundle on the client that makes AJAX requests to your API endpoints. Now your Javascript can call the same `api.fetchWhatever()` method, and await the result, and it works on the client and server (if you need it). It's a very nice pattern.
- epolanski 4y agoThus, you are confirming there is a hugh level of complexity. I want to add something else on top of what's in that gist: ssr is slow, rendering an application twice (on server and client) is just slow. We only do that for cache and seo, every other page suffers.
- stevebmark 4y agoI'm not sure what about two bundles causes a huge level of complexity. Granted, I use Next.js, it does all of this out of the box. SSR is fast, it's provably faster than client side rendering for first load. You can optionally do client side hydration, so the time to meaningful content is fast from SSR, and subsequent page loads are done SPA style (if you want). It's never a fair comparison, but Stackoverflow is entirely SSR (not Node.js) and it's very fast. Also, all forum software, which is SSR, despite being 20-30 years old, is usually faster than a SPA. The Jamstack is a recipe for loading spinners, not speed.
- com2kid 4y ago> Also, all forum software, which is SSR, despite being 20-30 years old, is usually faster than a SPA. Only because crap tons of hardware got thrown at the problem. I remember when forums were multi-seconds to load each page. It sucked. People complain about reddit a lot, but even on mobile, the reddit website is fast. It may be janky at times, but navigating between comments on stories is under a second, loading more comments is, well, not fast, but quick. Hacker News is notably one of the few non-crap forum sites out there. phpbb used to be everywhere, and it sucked everywhere. Up until 2012 or so, the old dial up BBSes from the mid 90s had a better user experience than the latest and greatest internet forums. (of course BBSs only had 1 client at a time, a much easier problem to solve!) And yes, phpbb works now, because now a cheap host has an SSDs with gigs of RAM. To do the equivalent of a what a 486 running DOS did back in 1993.
- dolni 4y agoPersonally, I'd much rather wait for a 1-2 second page load than have a page load quickly and peg one of my CPUs because of some poorly written Javascript.
- ConsoleTVs 4y ago> I remember when forums were multi-seconds to load each page. It sucked. You mean when you had the same internet speed 10 years ago, right...?
- PaulDavisThe1st 4y ago10 years ago in suburban Phila, I had 50/50. Today in rural NM, I have 40/5. Many of my neighbors have 25/2. Time is not the only thing that controls internet bandwidth.
- com2kid 4y agoI could pull 2 megabytes per second down back in 2000. I was at 5x that by 2010. My internet speed didn't really improve from 2010 to 2021, (Comcastic!) then I got fiber. File downloads are faster (800mbit gets binary fast), web pages are about the same. Servers have gotten faster, but ad tech had made crap slower. SSR won't help solve ad tech garbage making pages janky.
- Nextgrid 4y agoYou could exclude adtech from the equation using an ad blocker and theoretically make everything lightning-fast, but in reality adtech is not the only problem and non-ad JS also grew to consume all the available resources.
- briHass 4y agoIt's pretty hard to compare some random free PHPBB running on a underspec'd host to companies with billions in revenue to support their platform. Honestly, reddit and HN are so simplistic, there's not much added by JavaScript doing any rendering. Reddit in particular is horrific. Their API is slow, and their JS bogs down on anything that isn't a super-fast desktop. Server pages would be able to handle most of what they do, faster and better, except for crap like live updates or typing/posting indicators that don't add much value.
- sph 4y agoPoe's law in action. This is literally "to draw an owl, start with two circles and you're pretty much there."
- _hcuq 4y agoDouble the code. Double the bugs.