The JavaScript Standard Library
Written by Ian Elliot   
Wednesday, 13 March 2019

One of the problems with JavaScript is that there is no standard library as there is in other languages. This means that we have to download everything we need and not just the "extras". This is all about to change with a proposal to have browsers include JavaScript modules without downloading them.

JSlogo

It is difficult to know if this proposal, made by Ecma TC39, the committee that evolves JavaScript, is a good idea or not. The idea of a standard library for JavaScript is appealing, but the advantage of having built-in modules isn't quite so obvious. The proposal says:

"With the introduction of a standard library developers will get a well-defined API that does not have to be included with their pages or application. The functionality of the standard library will have gone through a standardization track and will have well-defined APIs and behavior."

The ideas is that built-in modules will be like regular modules, but always available. However, the advantage of this isn't as clear cut as it seems. It might be better to have modules that are downloaded and shared between all web pages or apps. In other words, instead of having them built in, browsers should implement a more intelligent cache to share common standard modules.

To smooth over any transition there are import maps, which tell the browser to ignore downloading a library if it is available as a built-in. This is almost the caching mechanism that is needed. If a browser doesn't support modules, and 80% do, then you need to fall back to loading code in the usual way.

There is, of course the big problem of deciding what goes into any standard library. The advantage of a standard library, ask any C or Python programmer, is that the objects in the library quickly become regarded as part of the language. This makes it easier for the community to work as a coherent whole. For example, currently if you ask how to do something you will get lots of answers telling you how to do it with jQuery or native JavaScript. The proposal doesn't seem to envisage including things that are specific to the environment that the code is running in:

"Such a library would only cover features which would be useful in JavaScript in general, not things which are tied to the web platform. (A good heuristic: if something would make sense on a web browser but not in node or on embedded devices or robots, it probably isn't in scope.)"

The proposal is at an early stage, but Google has already created the first built-in module for Chrome - KV Storage. This is a simple library that provides a key/value storage engine as an alternative to localStorage or indexedDB, both of which have problems. The whole thing is just an experiment at the moment, but Chrome has got built-in module support. If you want to try it out you need Chrome 74 and you need to turn on the experimental web platform features flag.

Although Google is taking the lead, it does seem to be a valid attempt at establishing a standard rather than a takeover or a feature that makes Chrome better than the competition. 

webfun

 

 

 

More Information

Standard Library Proposal

KV Storage: the Web's First Built-in Module

Related Articles

Survey Reveals JavaScript Trends

GitHub Removes jQuery. Why?

ECMAScript 2018 Is Feature Complete

ECMAScript 2016 Approved

JavaScript The Language With Two Names    

The JavaScript Encyclopedia Work In Progress 

JavaScript Added To Oxford English Dictionary 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


Go At Highest Rank Ever in TIOBE Index
20/11/2024

Go is currently in 7th place in the TIOBE Index for November 2024. Not only is this is the highest position it has ever had, it's percentage rating is almost equal to its all-time-high. Will Go contin [ ... ]



It Matters What Language AI Thinks In
23/10/2024

We are currently polarized in how we think about Large Language Models. Some say that they are just overgrown autocompletes and some say that they have captured some aspects of intelligence. How well  [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Wednesday, 13 March 2019 )