Skip to content

The simplest way to load ES modules or bundled fallbacks

Notifications You must be signed in to change notification settings

WebReflection/ecma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ecma

The simplest way to load ES modules or bundled fallbacks


How to

Just put on top of your HTML page (even before polyfills) the script tag with the following attributes:

  • data-module the ES2015 module entry
  • data-src the ES3/5 fallback

All browsers that are not implementing nomodule on script tags will be forced to use the fallback.

<script
  data-module="modern.js"
  data-src="bundle.js"
>!function(E,C,M,A){
  // if you don't care about full backward compatibility
  // M = E.querySelector(C + '[data-module]');
  M = E.getElementsByTagName(C)[0];
  A = M.parentNode.insertBefore(E.createElement(C), M);
  'noModule' in M ?
    (A.type = 'module', A.src = M.dataset.module):
    (A.defer = 1, A.src = M.getAttribute('data-src'))
}(document, 'script')</script>

As easy as that.

Compatibility

IE6 and above. Live test (it shows after one second on purpose)

ES6 / ES2015 Browsers

A list of browsers that will use native modules, hence fully compatible with ES2015 syntax.

This list destiny it to keep growing over time. Meanwhile, the bundled fallback will still work as it's already the case today.

Desktop

  • WebKit (GNOME Web, WebKitGTK+)
  • Chrome / Chromium

Mobile

No browser as of today ships with ES2015 modules support.

About

The simplest way to load ES modules or bundled fallbacks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published