Monday, November 27, 2017 [Tweets] [Favorites]

The Cost of JavaScript

Addy Osmani (via Hacker News):

On the high-end iPhone 8 it takes just ~4s to parse/compile CNN’s JS compared to ~13s for an average phone (Moto G4). This can significantly impact how quickly a user can fully interact with this site.

“Just?”

Using HTTP Archive (top ~500K sites) to analyze the state of JavaScript on mobile, we can see that 50% of sites take over 14 seconds to get interactive. These sites spend up to 4 seconds just parsing & compiling JS.

7 Comments

To be fair to JavaScript, a language for which I hold no particular affection, I'm sure that advertisers would do everything they could do to cram in as many annoying, CPU-eating, time-wasting ads as possible, no matter the choice of underlying technology. The problem is with the business model, not the tech.

"To be fair to JavaScript, a language for which I hold no particular affection, I'm sure that advertisers would do everything they could do to cram in as many annoying, CPU-eating, time-wasting ads as possible, no matter the choice of underlying technology. The problem is with the business model, not the tech."

While I certainly do follow your logic, I'm not sure it leads to the correct conclusion. I was surfing back in the 1990's, and there was a brief moment during the adoption curve of JavaScript when both JS and non-JS sites were trying like crazy to monetize via ads. The non-JS pages really were noticeably speedier to load and more responsive once loaded than the JS pages.

In other words, I think the problem is not so much JS itself as it is allowing any scripting language to exist in such a way that it can be hijacked for idiotic purposes in the browser. I assume it would have been possible to develop the modern web without a JS-like scripting language, had that path been foreclosed early on, and that a more vanilla HTML would've developed in such a way that it could've taken up the slack.

Somewhat like saying it takes a few seconds for the water in the shower to get hot; yes, I’d prefer that to not be the case, but I’m also not going to take cold showers.

On desktop, if I'm really interested in what the site/page purports to offer, I'll wait a little bit for it to load. On mobile, though, I won't wait; if I'm on mobile, I'm looking for something quickly, and slow/clunky/ad-overrun pages just get closed.

>I assume it would have been possible to develop the modern web without a JS-like scripting language

That depends on what you mean by "modern web", but if it includes things like Gmail or Google Maps, or even something simple like help with typing hashtags or @s in Twitter, then the answer is clearly "no, you need a general-purpose programming language, i.e. something like JS".

It's fair to complain about stupid JS abuse like CNN's, but if you're willing to gain 4 seconds of waiting while CNN loads for the price of a JS-free web, you're (and I'm trying to put this as kindly as possible) out of your mind :-)

"It's fair to complain about stupid JS abuse like CNN's, but if you're willing to gain 4 seconds of waiting while CNN loads for the price of a JS-free web, you're (and I'm trying to put this as kindly as possible) out of your mind :-)"

I must be out of my mind then. I do most of my desktop surfing in a browser where JS is disabled. That browser is where I read CNN stories. Other than my insanity, why would I do such a thing?

- While you can joke about 4 seconds, (and sometimes it's more), why should I endure a bizarre freeze before I can read a web page each and every time I click on something?

- When I read a CNN story, I get to read the text without the massive distractions I get when I try to read the story with JS enabled. I still see ads - it's not about avoiding them - but they aren't able to be as intrusive and distracting.

- I can keep 50 tabs open in my JS disabled browser, and have the app using 0% CPU. This is appreciated for various reasons.

- Just on general principles, I prefer to avoid running random server-side code every time I want to read something on the web.

When I use someone else's desktop computer, and read everything on the web with JS enabled, I tend to think everyone else is out of their mind for enduring it.

> why should I endure a bizarre freeze

Not saying you should. Like I said, it's a stupid abuse of JS.

What I *am* saying is that gaining 4 seconds at the price of going back to how the web was in the early 90s (i.e. static pages) is not a good trade-off. The web has been an incredibly amazing platform for application development. Giving all of that up to gain 4 seconds is a terrible bargain, particularly since, as you point out, you can just disable JS on your own personal browser, and gain those 4 seconds without also destroying 20 years of progress.

JS is being abused by a lot of websites. It's also enabled amazing new things. The idea that we would be better off without JS bears no relation to reality.

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment