Defaulting on Single Page Applications
zachleat.com
zachleat.com
SPAs can get this sort of thing too, but it's less automatic and generally requires framework support for keeping track of chunks of not-yet-visible, non-user-interactable inert DOM and matching them up with link clicks. Whereas with MPAs, because you're using the standard page rendering and link paradigm, the browser can manage for you.
Source: engineer on Chrome working on this feature :)
I recall Opera doing this sort of thing around two decades ago. It had a setting to aggressively cash all links, and navigating between those was instantaneously.
Is this what Chrome does?
Do you know of a React library for doing this? tanstack react-query can prefetch [0] but it just prefetches a REST API, it doesn't prerender in an invisible DOM node or something (also "prerendering" in React usually refer to server-side rendering of HTML text, not to prerendering something in the browser, so this seems a bit hard to search for)
[0] https://tanstack.com/query/latest/docs/react/guides/prefetch...
You can have an SPA with a proper router that respects page history, loads html fragments from a server, remembers positions on reload, etc.
You can also have a server side rendered page sprinkled with JavaScript and use web sockets to create dom element level transitions and interactivity
The “MPA” described in the article has always been possible in a “SPA.” It’s more about the UX of your app than anything else
SPA’s should be used web apps (think slack or Asana), and stick to sever rendered for web pages.
They have a waterfall of multiple API requests by the browser to display a single page. That means the front end has a bunch of logic to aggregate and piece together requests. This in itself isn’t a big deal, if you move to doing it on the backend you still have the same logic and need to make the same sub requests.
Where it does become problematic is it leads to fat API endpoints sending far more data to the client than is needed. GraphQL lets you choose what fields you query but odds are there’s still data available you can ask for that shouldn’t be asked for and sent to a browser.
If your requests/aggregations are done serverside it gives you a better chance of filtering out data that should never be accessible in the browser. You can also make full use of Cache-Control headers and backend caching.
Creating individual endpoints for web apps went out of fashion as it involves more effort and people don’t like effort to do things well. I see it re-invented recently as backend-for-frontend.
Not true, individual endpoints requires more work for client side optimizations but the CRUD query mapping effort is not reduced with graphql. If anything, graphql endpoints require more effort on the backend side to build because of having to wire up the resolvers unless you are using something like Hasura.
Everyone seems to agree on this, but if this is the case than i’m very confused why this is still a debate. The vast majority of developers are making apps, not “pages”. Pages are useful for a handful of well understood applications that already use CMS systems (blogs, ecommerce, forums etc). So why are we all pushing for MPAs instead of better apps?
You can’t get every detail right, because the browser doesn’t expose some of the pieces that would be required to do so—even apart from details that vary between browsers. The most obvious example of unexposed functionality is the loading indicator, but there are more around things like slow or failing networks.
When you refresh, the server renders some of it.
React seems like a bubble to me, created by fancy code that seems good at first glance but doesn't make a huge difference. What's it supposed to be amazing at, simple stuff or complex stuff? If simple stuff then why are people downloading 200K for Hello, World? If for complex stuff why isn't something like VSCode, Monaco, CodeMirror written with React? Those have state galore, and React's one-way data binding is no revelation for them. In fact inside React things like the ironically named react-hook-form get around React's one-way data binding by letting the form inputs be uncontrolled* (ironically named because react hooks makes it sound like it's going with the grain of react when it's thankfully going against it). Maybe ChatGPT will pop the bubble by churning out vanilla js that beats it. :)
* https://react-hook-form.com/advanced-usage/#Controlledmixedw... React Hook Form embraces uncontrolled components but is also compatible with controlled components.
As far as programming tools go I don't think we can call it a fad anymore.
* well maybe a collection of fads rather than a fad in itself
** I say this lovingly, it's similar to the magic of Steve Jobs and Apple. That said Vercel wouldn't interest me that much at this point if it was React-only. But the DX works for many different sorts of projects.
That's what they love to say, but it has never seemed that way to me. One way data flow seems to be a huge opinion.
Also dangerouslySetInnerHTML, htmlFor, className, etc, etc.
That last one was handled by the community, partly coming from Facebook, with stuff like GraphQL, but now they've gone more with batteries included route even on their website by suggesting to use a big framework: https://react.dev/learn/start-a-new-react-project
Also their opinions don't align with those of a lot of the community. A lot of glitches stem from controlled components.
"In most cases, we recommend using controlled components to implement forms" https://legacy.reactjs.org/docs/uncontrolled-components.html ( which they might have finally changed their position on https://react.dev/reference/react-dom/components/input#contr... )
"React Hook Form embraces uncontrolled components but is also compatible with controlled components." https://react-hook-form.com/advanced-usage/#Controlledmixedw...
Edit: I thought about it some more and the problem is that in order to see adoption, frameworks need to convince devs that they need something. With Vue what you have is reactive() and ref(). So they're convincing a lot of devs that they need MobX. Where in reality most devs don't need React's useState one-way bindings and they don't need MobX-like reactive objects either, nor do you need Signals from Solid. That said, if you prefer one of these, go for it!
Ergonomics of binding events and setting attributes/properties/styles is useful and I like how Lit, snabbdom, and Svelte provide ergonomics without one of these state management paradigms.
So if a problem exists about this scenario, it isn't about React, but how teams decide on tools. And unfortunately, most teams that aren't building their own solutions, go with the tool that has the largest "safest" community, not the one that accurately solves their issue.
What do you think about frameworks like Leptos that take the best of both worlds?
> progressively-enhanced single-page apps that are rendered on the server and then hydrated on the client, enhancing your <a> and <form> navigations and mutations seamlessly when WASM is available.
"I used this technique in my own emoji-picker-element. If you’re already using Svelte in your project, then you can import 'emoji-picker-element/svelte' and get a version that doesn’t bundle its own framework, ensuring de-duplication. This saves a paltry 1.4 kB out of 13.9 kB total (compressed), but hey, it’s there. (Potentially I could make this the default behavior, but I like the bundled version for the benefit of folks who use <script> tags instead of bundlers. Maybe something like Skypack could make this simpler in the future.)"
https://nolanlawson.com/2021/08/01/why-its-okay-for-web-comp...
Thing is I actually like coding in Vanilla JS, at least some of the time.
It really doesn’t matter. Master your tool and most of the supposed downsides can be avoided.
https://svelte.dev/blog/virtual-dom-is-pure-overhead
I have played thousands of bullet chess games on Lichees and is and was very snappy and used to be based on Mithril so it's very battle tested in a literal sense.
https://bestofjs.org/projects?tags=vdom
FWIW I disagree that something like virtual DOM can be pure overhead. It is useful to have virtual just about anything. Virtual filesystems for instance.
It doesn’t work for code editors because they need very close interaction with the DOM, whereas React provides an abstraction layer that covers the common cases.
1. Building apps with manual mutations (which is what we did before in the jQuery era). This involves a lot of boilerplate code, and it is hard to ensure that the UI state stays in sync with the app state properly.
2. Re-render the world on every state change. This works and allows you write simple code that is react-like in that it is pure transformation of app state into UI state, but it's slow and quickly runs into performance issues even in small apps.
1 still makes sense in the most performance sensitive scenarios. And 2 can work for the very simplest apps. But React and similar frameworks are great for everything in between.
> I don't see a whole lot of innovation from a computer science standpoint because the most complex js projects don't use it.
That seems silly. You could make the same argument for something like SQL. The most complex data manipulations won't use it. But it's still useful for the 90% that aren't that complex.
That's a lot of hand-waving weasel words to blame those experiencing problems for the naturally occurring problems.
If it was the same thing, we would not be having discussions on their pros and cons. This is not a team-specific issue.
Component design is the enemy here. Just take a peak at the nav elements in many designs and see how embedded the divs go.
* except media queries, those seem hard
When you put in the effort to build the components yourself, you aren't trying to be everything for everyone, so you get to skip a lot of the cruft.
That all said, I also have to ack that the libraries are going to be hard to beat for speed of delivery. :(
What pushes me towards using third party code is stuff like autocomplete search with drop-down selects, mostly because I don't want to mess up on the accessibility front, either keyboard navigation or screen readers, and there's at least a few that have that part figured out already.
And being fair, I'm sure this has gotten a bit better in recent years. But the Rube Goldberg efforts people would put in to get the "flow" of the browser to automatically place things in locations that were easily calculated is frustrating.
In an SPA clicking on something could replace the content in some other area of the screen - but if you don't add the right additional code the screen reader user has no way of understanding what just happened.
It's interesting to see technologies like livewire come out that take things back to basics.
In theory.
<button
title="Remove 'ABC' from cart"
hx-delete="/cart/123/item/abc"
hx-target="#item-abc">
Clicking this button will trigger a `DELETE /cart/123/item/abc` request and swap the response into the element selected by the `hx-target` selector. The response would be an HTML fragment. So instead of an API serving JSON you would have an API serving...HTML. It's a neat fit with any server rendering technology.I have yet to find a great guide to making SPAs work well with screen readers that goes beyond "read the ARIA spec" - but the ARIA spec isn't actually that useful for understanding the nuts and bolts of how you should build things so that e.g. screen readers know when the SPA has navigated to a new page, or loaded fresh content in a smaller page region.
My understanding is that MPAs are, by default, massively more accessible than SPAs. But my experience is that SPA authors rarely seem to indicate that they care.
I wouldn't be surprised one bit if Angular apps failed a11y audits at similar rates to React apps. But it isn't a problem with SPA's as an architectural concept, the problem is uneducated engineers.
Searching for "a11y [framework]" on GitHub gives good results and some "awesome" pages that link to resources on the subject.
Chrome is like the new IE, but far worse for user control and privacy.
I was gonna say:
"This is what some Hugo fans might say, but 11ty and Astro suggest otherwise."
Then I saw the author of the post is the author of 11ty.
Still, the middle ground is being pursued by Svelte and Fresh. I prefer something less frameworky though.
That's a moderately sized image.
That's <1s of 1080p video.
And that's assuming you haven't heard of a thing called "gzip."
At some point, I think we're finding things to be unhappy about.
From a performance perspective it's a bit of a wash. You get slower first page load and lots of spinners in exchange for faster navigation
So instead of having to download an entire HTML page and all the assets used every time you navigate, people built SPAs. Download everything up front, and then fetch data with small API requests. This way even though first load might take a while, everything is cached, and the client just needs to query the API for data.
The other side of it is that websites used to be pretty simple, and as browsers evolved past IE10, the kinds of things people build on the web also got more complex.
Don't browsers cache css, images, and JS and all that automatically for like 15 years now?
Just my anecdotal experience.
They usually follow the pattern of 3 seconds of hype followed by 10 years of digging out a mountain of technical debt from some asshole who has since moved on.
It looks really great, and I think Rails Hotwired / Turbo could really benefit from this API.
Of course, someone beat me to it: https://dev.to/nejremeslnici/how-to-use-view-transitions-in-...
So this is probably wildly naive, but I find myself wondering why SEO is so important still in 2023. Like, how much traffic is coming from Google that converts to paying customers or clients? I suppose it's industry specific, but for my friends that have sold product on e-commerce sites, the best way to make money seems to have been find a way to post on reddit for a given niche community without getting banned, and Instagram ads. Maybe Facebook ads.
For a SAAS, I'm really curious how much converted traffic comes from Google. When I need a SAAS I usually first ask all my friends, then start searching "service_i_need reddit sysadmin" to see what other people are using and their experience. Maybe I'll read a listicle from an aggregator i trust.
Also, you can just pay Google to be at the top of whatever search results, so you can Optimize by just giving them money.
Paid advertising and posting on social media has its place, but there are a LOT of people using Google and getting to rank 1 for important keywords usually works out cheaper than paying for the ad space.
It's impossible for shoestring apps to give Google money. They would fail at being businesses if they funneled money they didn't have to Google.
function main_state_changed(aState) {
main_state_display.innerHTML = loadFileFromServer(aState);
}
this way your app loads parts on on need basis. As for tooling - I do use minification but the rest is plain html, css and javascript and couple of selected libs. No frameworks and works wonders for me.It is amazing how modern web developers flock to that mess of frameworks and tooling to achieve what basic JS and no tooling do way more efficiently and with less time spent.
[0] - https://www.w3schools.com/jsref/prop_html_innerhtml.asp
I do not keep to single tool / strategy etc and use whatever I believe is the best choice for particular task. I write everything: firmware for MCU, multimedia apps with hardware accelerated graphics, enterprise backends and middleware, web front ends, device control and whatnot, so while some tech is universal the specifics can be highly different.
I guess we have different education and general background. I am 62 yo fart. Was raised in former USSR in a satellite town that existed soleily to accommodate bunch of scientists working in various fields. When not in school I would spend my time visiting my parent's place of work and got to play with very cool "toys" and people there were nice enough and let me "work" on tiny projects of various nature. I then done my M.Sc. in physics / biophysics and continued to work as a scientist. So I was basically trained to solve various problems in creative manner. Was never trained specifically in software.
I had wonderful teachers and mentors and can't ever express enough gratitude to them. Many of them are dead by now anyways.
During a course of my work as a scientist I needed to design various mechanical gizmos, electronics (digital and analog) and write some software since nothing existed for my particular field. I just got myself whole bunch of books and read and tried until I succeeded.
Then "perestroyka" started and I began to supplement my "official" income with writing a software as an independent consultant. Computer industry back then was very young, and I had no troubles finding contract work to create various products. My first side software project was PC based visual designer (something akin to music sequencer) to control lighting system for big theater.
I then immigrated to Canada and eventually ended up working basically as chief software product designer and implementor. First as an employee in software development company and then on my own.
As for diversity of the fields - when working on particular product I imagine software as a bunch of living components interacting with each other. I then nail down what those components and interactions are. I then get down to implementing it. Particular computer language, deployment platform and other pesky details are the last thing I worry about.
Over the years I've accumulated large portfolio of products and present those as a references when getting new contracts. I mostly deal with business owners and those do not give a flying fuck about languages. They want actual problems solved.
>"coding from scratch"
I do extensively use various libraries. But very specific problem oriented. Like graphics libraries. I avoid frameworks like a plague most of the time as those in my opinion degrade creativity and keep one hostage.
The failures need:
- Update the URL rather than depend on ephemeral DOM state like some damn Flash app
- Don't load the entire site all at once as one giant file
- Use server- and client-rendering wherever it makes the most sense
- Accessibility or be in a heap of legal trouble globally
- Get fancy by swapping js and html, but be prepared to deal with all edge-cases of things that don't know what magic is happening
Next and similar tools are decent if you NEED SSR and don't want to go the prerendering route - but there's some extra work involved.
Good point, I also think stimulusreflex.com deserves some highlight in this case too. This is where it shines!
https://v3-4-docs.docs.stimulusreflex.com/#faster-uis-smalle...
i do it like this: https://github.com/nathants/aws-gocljs
source: myself; someone who moved to working on a project entirely written in vanilla JS… which has just become its own bespoke framework.
This is mostly a bullshit answer that is hardly ever the case in reality and is pretty much always used as an excuse to favor developers over users.