Skip to content

Latest commit

 

History

History
76 lines (63 loc) · 3.2 KB

File metadata and controls

76 lines (63 loc) · 3.2 KB

Modern JavaScript

Modern JavaScript is often defined as ES6 (from 2015) or newer.

Legacy JavaScript is considered ES5 (from 2009). Older versions are obsolete.

Adoption

95% of browser traffic supports:

94% of browser traffic supports:

For the remaining 6% of traffic that doesn't support modern JS, we can transpile modern JS into older JS, at a cost to both bandwidth and execution speed of 6x or more.

  • 95% of web traffic comes from browsers that support ES2017.
  • 70% of web traffic comes from browsers that support ES2021.

Package Exports

The exports field in a package.json file was first supported in Node v12.8, which support ES2019 syntax.

Modern-only package.json

{
  "name": "foo",
  "exports": "./foo.js",
}

Modern with fallback package.json

{
  "name": "foo",
  "exports": "./foo.js",
  "main": "./foo-es5.js",
}

Client Fallback

For the 95% of browser traffic that supports ES8 from 2017, use:

<script type="module" src="app.modern.js"></script>

For the 5% of browser traffic that supports ES5 from 2009, use:

<script nomodule src="app.legacy.js"></script>

ECMAScript Versions

  • ES1: June 1997
  • ES2: June 1998
  • ES3: December 1999
  • ES4: June 2003 (abandoned)
  • ES5: December 2009
  • ES5.1: June 2011
  • ES6: June 2015
  • ES7: June 2016
  • ES8: June 2017
  • ES9: June 2018
  • ES10: June 2019

Resources