JavaScript Is the CO2 of the Web [audio]
changelog.com
changelog.com
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.
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.
Everyone else is just embracing them.
Angular, Vue, Polymer, Svelte and a couple of Web based RAD editors look like tooling to embrace them to me.
Since I don't have any plans to ever use React, how does your magical component work with my tooling?
If you use different tooling, then it doesn't work, and that's okay. You don't need to care about React and I don't need to care about Web Components. It was suggested that React is useless and should be replaced with Web Components, and I'm simply saying that Web Components are not sufficient to replace React, not that you should switch.
And best of all, they are even usable from React.
They alone are not a replacement for the entirety of frameworks, they are low level hooks that standardize the more fundamental level of frameworks: component instantiation, component lifecycle, and style and DOM encapsulation.
Higher level features like DOM rendering are left to libraries, and there are some really good libraries for that. And I'm not sure what you even mean by the libraries limiting what you can do how you can develop. There's way more choice in the web components ecosystem than within any single framework.
`document.querySelector('div').someProperty = {some: 'value'};`
For DOM updates you will generally use a declarative DOM rendering engine like lit-html, just like how you use React's VirtualDOM. In fact, the most popular Web Component "library" [LitElement](https://lit-element.polymer-project.org/) uses very simlar vernacular as React (like the `render()` method), and from a developer perspective feels exactly like using React, except it relies more on builtin platform features.
A small demo https://jsfiddle.net/zu52o7bq/.
These are not React-like components - independent reusable universal blocks that can be used without any knowledge of the component other than that it uses React.
I just proved you wrong with this simple demo, so you waved that away and pulled out hooks argument.
How is that related is beyond me (not to mentioned hooks are fresh in react world too). If you want to have a discussion at least have decency to not change subject randomly, it is annoying.
BTW. You can use both hooks (via haunted project) or redux (lots of people do that) with WC's just fine. In fact I wrote code that looks almost the same in react and lit-element.
Hooks are an extension of that - it is a different way to pass values around, a very powerful one.
See here https://custom-elements-everywhere.com/ a list of popular libraries and how they handle events and props.
Jesus Christ what is going on with the web.
> You still can't just search and be using a new application nearly immediately.
You can't? I sure can. Gnome, kde, and Mac all have great ways of searching through your apps. The windows search is a little crap.
But the great thing about a local, native environment is that the user is actually in control. If there is an app I need quick access to, I can map it to a shortcut or desktop icon. That's way faster that searching and scrolling through results.
From my non web dev perspective, the reason there is such a proliferation of bloated web apps is because of the devs. All of a sudden we have a ton of developers with little to no formal training who want to make cool apps instead of good products. So they layer on plenty of dependencies. And when there's a Cool New Framework© next week, they'll incorporate that too.
I just don't think devs have performance and user experience as number one priorities. The web will always be horribly slow compared to an SSD. In my opinion, the web has a couple of other fatal flaws that make it inferior to native for applications. But if we do want the web to be where all our applications to live anyway, we need to be concerned about performance as a high priority.
He was talking about using new apps, not already installed ones.
And the Windows search works fine as long as you disable Cortana... As sad as that is.
This is a nice idea, but it’s far faster to search with mail.app. The great thing about gmail is just labels.
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.
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!
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.
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.
--
[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?
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)?
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.
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.
let f = (a, b) => a + b
can be considered prettier (or clearer) than let f = function (a, b) { return a + b }
or (given the differences in runtime behavior) function f (a, b) { return a + b }
It saves typing for trivial functions, sure, but it's yet another syntax for the same thing.1) Less tokens: less noise, more signal. `a + b` is the important part, let's not obscure it.
2) Lexical `this` binding.
3) Shorter and less likely to line-break.
4) No hoisting when used with let and const
5) Actually const when used with const. const module exports are faster.
The only downside is you've got to involve babel to transpile it down to the shitty old browser versions that we need to support, so you go from a simple reload to a webpack or grunt invocation that takes 30 seconds to a couple minutes, depending on how invasive the corporate anti-virus is feeling today.
I'll read more about lit-element. Thanks :-)
It seems many of the JS frameworks add a lot if, IMHO unnecessary, complexity.
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
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.
You know, I guess that's why I come to think more and more that I have a real issue with the attitude of some of the more deeply technical folks: You completely neglect the success of this ecosystem and what it does for all of us, because of technical details that apparently do not matter a lot to end users.
Yes, for technical people having to deal with that ecosystem, it can introduce new quirks and issues. It's your job to deal with that and create value for customers.
Do something about it instead of ranting and whining.
My final comment would be success of proliferation isn't always a result of quality. I am not saying it doesn't provide value - it is just a very poor programming language which, being popular, means people who learn professionally my get stuck in a minefield of dogma instead of focusing on sound principals.
https://hackernoon.com/how-it-feels-to-learn-javascript-in-2...
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.
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.
--
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...
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.
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.
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.)