Too much JavaScript is bad, no JavaScript isn't better
I'm currently working on a proposal to revamp the design and user experience of the Sourcehut open source project. One of the most common feedbacks I got from its users was to not add JavaScript to the project. It was not a surprise, as I am spending a lot of time on the fediverse with nerds people who rely on second hand electronics, bad/expensive internet connection, or are just non-wasteful by philosophy and aren't keen to see any JavaScript loom into their favorite websites or projects.
And sincerely, despite being a front-end web developer that likes this language, I totally get why it gets such bad press.
For the last ten years, the JavaScript powered websites methodology (as in: HTML is generated by JavaScript) was used in situations where it was stupid and unproductive. Way too many people confused applications (example: Google Maps) with interactive documents (example: Twitter), creating heavy, under-performing, battery draining websites ; especially on aging computers and phones, forcing hardware replacement for no reason (and let's not talk about tracking and ads, uh).
Quite logically, an "anti-JS" sentiment took form, with people wanting websites without JavaScript at all, as it makes those more usable on their older hardware and software (and for some, more secure).
But despite understanding the feeling, I can't really agree with the conclusion. Despite my job title, I don't love npm install
-ing gigs of code from the internet and serving you loading spinners while I rage against my package.json
updates. I'm not the developer advocate of an evil corporation soft powering you into my monopolistic tribe.
I disagree because I feel this "anti-JS" idea is as exclusive as the "pro-JS" side that birthed it, and because both sides disregard either the technical or human capabilities of their users by taking a scorching earth approach at solving their own issues.
JavaScript is a double edged sword
The web has been widely available for twenty years, but they are still a lot of people who did not get used to it. Digital divide is a real thing, with a lot of users struggling when using our websites, both on computers or phones. And if we decided to totally ban JavaScript from the web, those people would have an even harder time than they do now due, to a massive degradation of their user experience.
Let's take a few examples.
- A simple JavaScript shopping cart is easier to use and requires less resources than automatically being redirected to a cart page each time you add something into it by pressing a button.
- A tax calculator that updates in real time when you enter data, and tells you in real time what you're going to pay, is less stressful, more efficient and requires less back and forth than a page based experience.
- An insurance company offering a complex subscription tunnel composed of a dozen of pages is a non-ending, unnavigable mess ; that could be replaced by several smaller forms, stacked onto each others, which can be saved, edited and reduced on the fly, all in a single page.
- Someone with dyslexia that needs an adapted design would have to go into its configuration panel to select a dyslexia mode in a form, then validate it, which would reload the whole website with a new stylesheet. It could be replace by a simple toggle button, without reload, in any page.
A one size fits all JavaScripty solution like we have today excludes people economically, promotes environmental waste and capitalism. But a one size fits all non-JavaScripty solution is ableism disguised as techno resistance. You could think that the latter is better than the former, but in reality we can solve both problems by making JavaScript not be mandatory on interactive documents and using it as a user experience enhancement tool.
That's what progressive enhancement and graceful degradation are made for, and they already work very well. You should equally be able to get housing benefits by struggling one hour on your Playstation Portable with a basic user experience if that's all you have, or in five minutes on a recent iPhone by using an automatic form filler that picks your data locked with your fingerprint.
Websites that find the right balance between user experience and technical capabilities are already a thing. Promoting a pro or anti JavaScript sentiment is a retrograde approach at a time when we have the tools and knowledge to do better. And it's not just me thinking this. The mindset around JavaScript usage is already shifting in the industry, with more people promoting a more responsible approach, and tools adapting to this new reality.
JavaScript evolves towards less JavaScript
Most of the frontend frameworks à la mode are now used in meta-frameworks (with Next being the leader) that provide server side rendering with interactions (yes, they are recreating PHP and Jquery duh), thus working on older hardware. Some of those frameworks are not even libraries anymore, but compilers (like Svelte) that outputs super tiny and efficient code, far from the bloat we currently experience.
We've seen the rise of micro-frameworks that work exactly like their fatter counterpart, but are 10 times smaller (Preact vs React) and most of them are even faster. We're even witnessing the creation of Frameworks that compile to HTML and create "islands" of JavaScript interactions, combining the best of both world (that's Astro), even if all of them don't yet have an answer when JavaScript is disabled (but Remix does and seems impressive on this aspect).
Of course all those previously mentioned frameworks rely heavily on a massive ecosystem of tooling which is still problematic, unsecured, brittle and way too heavy (and most of it, owned by Microsoft now). But at least the user experience they output is starting to empower their users instead of their developers. And for folks that don't like NPM but still want to compile JavaScript, there are single binaries like (esbuild) that you can just install on your system and use the way you want.
And finally, if you truly hate JavaScript to the point you don't even want to write it for the sake of your users, there are great libraries who can manage interactions through HTML attributes (HTMX, Alpine) for Ajax calls or dom interactions. They already have a lot of success in non-JS culture teams like Python, Ruby or even JAVA.
This is not to say that everything is perfect. It's still gonna take years to undo the damage that Angular and React did to the web while keeping their benefits. But things are progressing in the right direction and maybe, soon, we'll be able to have websites that don't look and feel like a 2005 page, while visiting them on a 2005 computer.
So yes, please, let's use JavaScript. But responsibly.