JavaScript

A recurring theme in my writing and talks is “lay off the JavaScript, people!” But I have to make a conscious effort to specify that I mean client-side JavaScript.

I thought it would be obvious from the context that I was talking about the copious amounts of JavaScript being shipped to end users to download, parse, and execute. But nothing’s ever really obvious. If I don’t explicitly say JavaScript in the browser, then someone inevitably thinks I’m having a go at JavaScript, the language.

I have absolutely nothing against JavaScript the language. Just like I have nothing against Python or Ruby or any other language that you might write with on your machine or your web server. But as soon as you deliver bytes over the wire, I start having opinions. It just so happens that JavaScript is the universal language for client-side coding so that’s why I call for restraint with JavaScript specifically.

There was a time when JavaScript only existed in web browsers. That changed with Node. Now it’s possible to write code for your web server and code for web browsers using the same language. Very handy!

But just because it’s the same language doesn’t mean you should treat it the same in both circumstance. As Remy puts it:

There are two JavaScripts.

One for the server - where you can go wild.

One for the client - that should be thoughtful and careful.

I was reading something recently that referred to Eleventy as a JavaScript library. It really brought me up short. I mean, on the one hand, yes, it’s a library of code and it’s written in JavaScript. It is absolutely technically correct to call it a JavaScript library.

But in my mind, a JavaScript library is something you ship to web browsers—jQuery, React, Vue, and so on. Whereas Eleventy executes its code in order to generate HTML and that’s what gets sent to end users. Conceptually, it’s like the opposite of a JavaScript library. Eleventy does its work before any user requests a URL—JavaScript libraries do their work after a user requests a URL.

To me it seems obvious that there should an entirely different mindset for writing code intended for a web browser. But nothing’s ever really obvious.

I remember when Node was getting really popular and npm came along as a way to manage all the bundles of code that people were assembling in their Node programmes. Makes total sense. But then I thought I heard about people using npm to do the same thing for client-side code. “That can’t be right!” I thought. I must’ve misunderstood. So I talked to someone from npm and explained how I must be misunderstanding something.

But it turned out that people really were treating client-side JavaScript no different than server-side JavaScript. People really were pulling in megabytes of other people’s code to ship to end users so that they could, I dunno, left pad numbers or something.

Listen, I don’t care what you get up to in the privacy of your own codebase. But don’t poison the well of the web with profligate client-side JavaScript.

Responses

Paul Morriss

I agree w/ adactio.com/journal/19531 about too much javascript. I saw a tweet “what’s the most important thing to decide for a new web project?”. Answers were serious so I didn’t chip in, but I think it’s “deciding what animated icon to use while downloading all. that. javascript.”

Joseph Scott

“To me it seems obvious that there should an entirely different mindset for writing code intended for a web browser. But nothing’s ever really obvious.” — so much this, they share syntax, everything else should be considered different adactio.com/journal/19531

Tane Piper

@Aaron when we were building our game engine in 2001 we used Spidermonkey as the the scripting engine for missions.

# Posted by Tane Piper on Tuesday, November 22nd, 2022 at 7:45pm

ppk

@Aaron Netscape Something Server.

# Posted by ppk on Tuesday, November 22nd, 2022 at 8:01pm

1 Like

# Liked by Marty McGuire on Wednesday, October 19th, 2022 at 4:46pm

Related posts

Schooltijd

Going back to school in Amsterdam.

Switching costs

The enshittification of React …which was already pretty shitty for users.

event.target.closest

DOM scripting and event handling.

Speedy tunes

Improving performance on The Session.

Web Audio API update on iOS

The behaviour is more consistent now.

Related links

HTMX Is So Cool I Rolled My Own! – David Bushell – Freelance Web Design (UK)

Call it HTMLX or call it Hijax, what matters isn’t the code so much as the idea:

Front-end JavaScript fatigue is real. I’m guilty myself of over-engineering JS UI despite preferring good old server templates. I don’t even think HTMX is that good but the philosophy behind it embarrasses the modern JavaScript developer. For that I appreciate it very much.

Tagged with

SCALABLE: Save form data to localStorage and auto-complete on refresh

When I was in Amsterdam I was really impressed with the code that Rose was writing and I encouraged her to share it. Here it is: drop this script into a web page with a form to have its values automatically saved into local storage (and automatically loaded into the form if something goes wrong before the form is submitted).

Tagged with

What Is A Single-page Application?: HeydonWorks

You can’t create a complex modern web application like Google Mail without JavaScript and a SPA architecture. Google Mail is a webmail client and webmail clients existed some time before JavaScript became the language it is today or frameworks like Angular JS or Angular BS existed. However, you cannot create a complex modern web application like Google Mail without JavaScript. Google Mail itself offers a basic HTML version that works perfectly well without JavaScript of any form—let alone a 300KB bundle. But, still, you cannot create a complex modern web application like Google Mail without JavaScript. Just keep saying that. Keep repeating that line in perpetuity. Keep adding more and more JavaScript and calling it good.

Tagged with

JavaScript Bloat in 2024 @ tonsky.me

This really is a disgusting exlusionary state of affairs.

I hate to be judgy, but I honestly wonder how the people behind some of these decisions can call themselves web developers.

Tagged with

scottjehl/PE: declarative data binding for HTML

This is an interesting idea from Scott—a templating language that doesn’t just replace variables with values, but keeps the original variable names in there too.

Not sure how I feel about using data- attributes for this though; as far as I know, they’re intended to be site-specific, not for cross-site solutions like this.

Tagged with

Previously on this day

4 years ago I wrote Continuous partial browser support

Treat every browser feature like an experimental feature.

16 years ago I wrote Announcing Huffduffer

I maded you a website.

19 years ago I wrote Back from Brussels

I spent the weekend in Brussels attending the Euro IA summit… well, kind of.

20 years ago I wrote Ch-ch-ch-changes

I’ve been doing some spring cleaning around here (if you’re reading this in an RSS reader, you might want to visit the site to investigate some of the changes).

21 years ago I wrote Elite

Yesterday’s magazine section of The Guardian included an extract from a forthcoming book entitled "Backroom Boys: The Secret Return of the British Boffin" by Francis Spufford.

23 years ago I wrote The Nobel Prize in Physics 2001

I was in the post office a few days ago to get a stamp. I needed to send a card to the States which costs 65p.