es6pack
v0.10.3
Published
Safe and performant ECMAScript 2015 script loading for the browser.
Downloads
3
Maintainers
Readme
Safe and performant ECMAScript 2015 script loading for the browser.
Installation
$ npm install es6pack
Purpose
- Use ECMAScript 2015 (sans "transpilation") and contemporary browser APIs as progressive enhancement without bothering the little guy.
- Expose the conditional script resource URLs to the preload scanner.
- Load the script resources in parallel without blocking page rendering.
- Execute the loaded script resources in source order.
Declarative API
- the
HEAD
element must have anitemscope
attribute - resources are declared with
LINK
elements that have- a required
itemprop
attribute with one of the following valuesstyle-resource
script-resource
- a required
href
attribute with the resource URL - an optional
media
attribute with a media query- for script resources, the media query is only evaluated once, when the bootload script is executed; use it with caution and common sense
- an optional
rel
attribute with a resource hint value of sorts
- a required
- the bootload script itself succeeds those
LINK
elements
Since the bootload script should always be included inline, the module exports the script as a string that can directly be used with a template engine.
Normal style sheets links should be placed after this inline script because the CSSOM blocks script execution: https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/
React example
const es6pack = require('es6pack');
[...]
<head itemscope>
[...]
<link itemprop="style-resource" href="beep.css" />
<link itemprop="script-resource" href="beep.js" />
<link itemprop="script-resource" href="boop.js" />
<script
dangerouslySetInnerHTML={{__html: es6pack}}
></script>
<link href="mobile-first.css" rel="stylesheet" />
</head>
ECMAScript 2015 feature tests
eval
ed
- const declaration
- let declaration
- arrow function
- default parameter
- template string
- object destructuring
- generator function
- for/of loop
- yield
- spread
- class/extends
Global objects
Map
Promise
Proxy
Reflect
Set
Symbol
WeakMap
WeakSet
Host objects feature tests
MutationObserver
WebSocket
Worker
fetch
matchMedia
requestAnimationFrame
document
has the methodsgetElementsByClassName
querySelectorAll
HTMLElement
instances have aclassList
objectHTMLScriptElement
instances have a booleanasync
IDL attribute- SVG can be used in HTML
Example
$ npm run prepublish
$ cd example
$ npm start
License
MIT