3 ms·
IMO the critical thing needed to stop JS bloat is a decent standard library. The _vast_ majority of code on an average site tends to be the same thing implement
by mbell 8y ago
IMO the critical thing needed to stop JS bloat is a decent standard library. The _vast_ majority of code on an average site tends to be the same thing implemented 45 times because the stdlib in Javascript is anemic. The current process of adding a function at a time to the language spec is rather pointless at solving this issue since it's often years after the function is added before anyone can realistically rely on it existing. In the mean time we have to keep loading polyfills just in case. Also at the current rate of functionality additions it'll be decades before the stdlib is decent.
What I really want to see happen is WHATWG start a standard lib project. In my mind it would look something like this:
* Open source project that implements the standard library in Javascript only and holds the canonical test suite. Something akin to core-js but the 'official' version of it and with features outside the language spec.
* Every browser agrees to preload / cache all recent versions of the standard library (or most recent version for each major release assuming semver). This allows all programmers to load the version they need without concern for the performance hit.
* User loads the standard library via a script tag with src something like: https://ecmascript.org/stdlb/v1/lib.js https://ecmascript.org/stdlb/v1/lib.js. Doesn't really matter what it is, just some recognized url the browser knows about that encodes the version.
* Each browser can provide a native implementation of anything in the stdlib so long as it passes the spec. Browsers could even optimize which pieces of the stdlib it parses / loads based on this. e.g. If the browser has a native Promise implementation then it doesn't need to load the Promise code from the stdlib.
* Be reasonable but aggressive about adding to the stdlib. It's scope should be wide and cover common use cases. e.g. I shouldn't have to write a URL parsing class or a throttle function every time I start a new project (which is where we are today). There are plenty of projects to look at for learning what people need (lodash, etc).
Obviously this would not cover everything; it's not going to add `await` to browsers that don't support it. But I think we're at the point where what we are most in need of is not language features (and mostly these are transpilable anyway), but stdlib functionality.