105 points · by feross · 7y ago · 124 comments
For 5 or so years I've been the guy who immediately started a SPA and I've turned 180 degrees. I now think SPAs are basically a cancer, with some exceptions where an app-like website is justified (Gmail, etc) or a hybrid app. SPAs introduce unnecessary complexity and bloat for the vast majority of use cases.
Jesus Christ what is going on with the web.
I've had similar experiences with scaling too early into microservices for example. I need a seriously compelling reason to consider building around these paradigms now. The overhead is unreal.
Both great ways to solve a problem, but not really a problem I've yet encountered - ever.
I'm still glad I've had great opportunities to learn this, at least.
And with WebComponents being supported across the board, even less so.
My current side project is a HTML sprinkled with JS, turn off JS and you can use most of the site kind of thing. Why? Because ... well mainly SEO to be honest. But there you go ... reasons!
It does. But, depending on how you look at it, either most web companies absolutely suck at picking right tool for the job, or the job isn't really what you'd think it is.
Taking your typical plain webpage done as an SPA, you could either say (as I would) that the authors picked wrong tool for the job, introducing completely unnecessary complexity both on their end and customer end - or, you could tell that the job of that website isn't to be useful to and considerate of the visitor, but to be e.g. CV-fodder for web developers, a way for the team to show off their sophisticated infrastructure, or for the marketing to play their A/B testing shenanigans, or for the company to show off to the investors, etc.
Once you account for all the "parts of the job" that are orthogonal or even opposite to delivering value to users, suddenly a proliferation of frontend complexity makes perfect sense.
Now onto the js frameworks, it depends on which one is used. One could build a website watching web.dev and use a budget to make sure it's app is lightweight. There are numerous tools to make sure an app is properly made. But tbh, I like my js framework because the community is so great, I know the framework is good even tough there are arguments there and there.
I guess it all depends on the tool you choose and how you build your end product. Now having a website that loads in 30s is a joke I haven't experienced in the modern web, and my js framework actually provides a powerful caching system that makes the website available even tough I could bring down my dns. To this point I presume we are just in a odd point in web evolution where we have discovered a new paradigm and rushed into it's usage without maturity.
These things will change but I think it is important to know that some JS front framework are not incompatible with a lightweight web.
The problem is that most of the popular frameworks today add unnecessary complexity.
I still can't believe that we live in a world were most developers are OK to coding with a 5 to 15 second build delay and source mapping during development. I find is extremely frustrating. It slows me down and breaks my train of thought.
Like? I am curious: built a few SPAs (quite complex ones) and it sucked; I got the tools/frameworks from HN.
If you use the right tools ‘tradional’ websites are not complex either.
I think SPAs are good when you have to handle a lot of dynamic data. Especially realtime data.
I built a sample SPA with VueJS, Asyngular and RethinkDB to demo how easy it is.
It's a relatively complex app where all the views update in realtime but all the server code is less than 300 lines.
The framework does most of the work; on the back end, all you need to do is define the data schema and access control rules on the server side. See https://github.com/SocketCluster/ag-crud-sample/blob/6805499...
For the front end, I use VueJS in the simplest possible way without any build step during development. I just define my main app component and setup a component for each page: https://github.com/SocketCluster/ag-crud-sample/blob/master/...
For data, I just use my own model and collection components to bind to the server data in real-time: https://github.com/SocketCluster/ag-crud-sample/blob/master/...
The collection component lets you bind to a 'view' which is declared in the schema on the server.
It's just CRUD with realtime subscriptions built into the model and collection objects, nothing special.
You can achieve a lot more if you just keep things simple (at least conceptually) and use the right tools.
--
[0] - I used React a bit, and I can only stomach it when working with ClojureScript, which gives some sanity to the syntax and language - but that's another pretty large and very complex dependency to be included in the pipeline!
I haven't listened to the audio, but all it takes to get rid of JavaScript-heavy pages (that only exist because young webdevs are being taught and drool about mostly JavaScript, React, and other overkill rather than web basics), we just need to step up the game and demand power-efficient webapps, or no webapps at all.
The static pages are in static HTML, because of course they are.
But the product pages need to be interactive. To do that, I need to use JS, and an SPA framework (I use Vue) makes that easier and way less effort than (e.g.) JQuery.
I have one problem, though... the marketing folks want to be able to change the copy on the static pages, but they don't want to learn HTML. They're pushing for me to implement the static pages as a Wordpress site, with a list of pluging that they want, because that's what they're used to.
I don't think JS is the problem here...
Vue Router, a plugin, adds the SPA functionality.
I wonder how much of this is a reaction to the complex and volatile nature of frontend patterns, in a psychological sense.
tl;dl around 20:45: They're comparing javascript and the tools you use for it to transportation modes. Saying things like Angular was the H2, React is the H3, vanilla javascript is riding a bike. They really are just saying don't over engineer things and use the right tools for the job.
Douglas Crockford's Javascript the Good Parts, is imo the best when it comes to getting a feel for what the right/wrong tools are. That book was a perspective changer for me. People like to get very passionate about frameworks and how Javascript should be done. JS The Good Parts made me realize it's better to play the strengths of what's available to you here and now. To accept the tooling as it is with its pros and cons - exploit the strengths and minimize the impact of the cons.
So... use what?
I like that Vue can be "dropped in" to any HTML page, like jQuery, without completely taking over the frontend development process, but it still weighs in at 30k. Also, the Vue docs are primarily oriented towards a pre-processing SPA workflow.
Are there any light-weight libraries like Vue, around 2k-5k, that enhance static HTML with declarative DOM manipulation reactive data binding?
Is there a "plain JS" approach to declarative DOM manipulation?
Think of a "modern best-practices" site that uses a big framework and some big addons and feature libraries, and ends up with like 500 KiB of JS. Some end up with megabytes! That's crazy. I think these developers don't have a sense of scale. They probably think I promote premature-optimization, that they're good engineers who follow best practices and use best-in-class tools and techniques ... but they don't have a sense of scale to see how the results are not reasonable.
30 KiB is small. 100 KiB total is probably quite OK. 500 KiB is very fat. 2 MiB is crazy town. Sense of scale :)
I can probably stick with the 20KiB Vue dependency, particularly when it doesn't require any build system or other dependencies.
I'll read more about lit-element. Thanks :-)
Why?
This function looks perfectly 100% normal to me, but that's probably I spent a whole workweek once almost entirely in ObservableHQ documents, where you'd use md`...`, html`...`, etc. all the time.
and this https://youtu.be/AdNJ3fydeao
Disclaimer: I'm one of the maintainers.
Can Preact just be "dropped in" to an existing HTML template, like jQuery?
Basic MVC goes pretty far
Is there perhaps a library in the 2k-5k range, or somehow a way to use only specific parts of Vue (like a custom build)?
--
It is such a mess that it is now mainstream to compile some metajs langauge to js.
Is it the worst language every created? Certainly not, but is it the worst language being actively developed and used? Yes. Is it poisoning the minds of young programmers with bad practices and a fear of concurrency? yes.
Other languages (and newer versions of JS) compile to ES5 so they can be run in JS engines supported by commonly used browsers. Not because JS itself "is such a mess". This allows one to roll out new language features to developers without having to wait for browsers to pick up a new standard (or language). Pretty much every language I am aware of adds new features and changes over time. Do you call them a mess also, because they make changes?
I think your comment is highly opinionated, not well supported by facts and sources, and IMO on the edge of being insulting to a lot of people.
TL;DR JS has become more of a target over time than a source which might be a hint that there is something deeply wrong with it. People wouldn't reinvent the wheel if it was round to begin with.
And JS is evolving, faster in some areas than others but it is evolving. Compared to the first time I used JS, now its very convenient language with some quirks. But the main reason actually it is rising in popularity so much is that's probably the most cross platform language today. And I am ot talking about what you compile language to, I mean what do you use to ship software to people.
The problem is not JavaScript the language, the problem is abusing client side programming. I can't imagine what kind of perfect language could have prevented that. If you can, I won't believe you, sorry. The feature that matters, sandboxing, it's there yet.
1) No memory limits (technically, there is a limit, but it is much bigger than, say, app heap limit on Android)
2) Background tabs can use setTimeout() to indefinitely run code long after user left them
3) Websites can start background processes (Service Workers) without user oversight. Users can't prohibit that or kill them via easily available means.
4) Applications are non-optimized by default, need massive CPU resources for JIT-compilation
5) Rendering a page with five sentences requires executing tons of said unoptimized code.
6) No permission system for majority of things. All important user controls have to come with browser add-ons.
7) Applications can update themselves anytime without user consent
8) Most web apps do not work offline
9) Everything is tied to proprietary web services with overarching surveillance and dodgy EULAs...
It's ironic that JS as a language is hated to the point of near derangement on HN while being the least relevant component of the problems people here have with the modern web.
there was a whole thread here a few weeks ago hating on SQL (a battle-tested veteran of ~50 years) and giving a laundry-list of "things that are broken in SQL"
there are routine threads discussing the manifest flaws of Go, and why everyone should switch to Rust/Elixir/Nim/whatever the newest flavour is.
no language is perfect (not even LISP), every language is a bit broken in some ways.
JS is a great language for its role. It allows newbie coders to write some godawful web code that works!!!1!1!! while they're learning (without having to understand a lot of CS), and veteran coders to write some really elegant code if they want.
Learning to use JS powerfully has been a great education in coding for me. I'm still not using it as well as I could be using it, and I like that it has depths still to discover.
Better than using other static site generators sprinkled with JS?
I've not done any research yet, so curious to know what the HN community thinks.
No, I'm not a JS hater, In fact I LOVE VueJS and I think you can do a lot of great things with it. For example, I built a completely offline cart system without any server backend using just VueJS. But then, between VueJS and something like LiveView, I find its infinitely easier and faster to develop on vanilla server-powered CRUD applications than SPA/JS only frontends with "serverless" backends.
With each year in web development, the complexity only seems to keep increasing to get something as simple as loading a web page fast or without refresh.
These days, I've started using LiveView and Turbolinks which basically means I have absolutely no necessity to touch Javascript at all and I can get everything done with the same language I write for my backend - Elixir. It's pretty amazing.
Much love to José and Chris.
Also, being able to use the language directly in the browser is a pretty useful property.
In the case of the web, the utility of javascript comes from being able to script the DOM and execute code in a browser. If there were other languages which could also do so (as was the original intent implied by the <script> tag,) those languages would also be at least as useful as javascript.
(Then, web developers would be cows, and web fashion/standards would be food for said cows; unlike in real life, here we transitioned from algae-based food to whatever farmers shove into livestock today, making the cows start burping large amounts of methane in the process. NPM would be an open-air landfill.)