Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit a063ae3

Browse files
committed
kevin review
1 parent a850f72 commit a063ae3

1 file changed

Lines changed: 33 additions & 22 deletions

File tree

README.md

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,54 @@ A suite of polyfills supporting the [Web Components](http://webcomponents.org) s
99
- **HTML Imports**: a way to include and reuse HTML documents via other HTML documents ([spec](https://w3c.github.io/webcomponents/spec/imports/)).
1010
- **Shadow DOM**: provides encapsulation by hiding DOM subtrees under shadow roots ([spec](https://w3c.github.io/webcomponents/spec/shadow/)).
1111

12+
For browsers that need it, there are also some minor polyfills included:
13+
- [`HTMLTemplateElement`](https://github.com/webcomponents/template)
14+
- [`Promise`](https://github.com/stefanpenner/es6-promise)
15+
- `Event`, `CustomEvent`, `MouseEvent` constructors and `Object.assign`, `Array.from` (see [webcomponents-platform](https://github.com/webcomponents/webcomponents-platform))
16+
1217
## How to use
1318

1419
The polyfills are built (concatenated & minified) into several bundles that target
1520
different browsers and spec readiness:
1621

17-
- `webcomponents-hi` -- HTML Imports (needed by Safari Tech Preview)
18-
- `webcomponents-hi-ce` -- HTML Imports and Custom Elements (needed by Safari 10)
19-
- `webcomponents-hi-sd-ce` -- HTML Imports, Custom Elements and Shady DOM/CSS (needed by Safari 9, Firefox, Edge)
20-
- `webcomponents-sd-ce` -- Custom Elements and Shady DOM/CSS (no HTML Imports)
21-
- `webcomponents-lite` -- all of the polyfills: HTML Imports, Custom Elements, Shady DOM/CSS and generic platform polyfills (such as Template, ES6 Promise, Constructable events, etc.) (needed by Internet Explorer 11)
22+
- `webcomponents-hi.js` -- HTML Imports (needed by Safari Tech Preview)
23+
- `webcomponents-hi-ce.js` -- HTML Imports and Custom Elements (needed by Safari 10)
24+
- `webcomponents-hi-sd-ce.js` -- HTML Imports, Custom Elements and Shady DOM/CSS (needed by Safari 9, Firefox, Edge)
25+
- `webcomponents-sd-ce.js` -- Custom Elements and Shady DOM/CSS (no HTML Imports)
26+
- `webcomponents-lite.js` -- all of the polyfills: HTML Imports, Custom Elements, Shady DOM/CSS and generic platform polyfills (such as ES6 Promise, Constructable events, etc.) (needed by Internet Explorer 11), and Template (needed by IE 11 and Edge)
2227

23-
If you are only targetting a specific browser, you can just use the bundle that's
24-
needed by it; alternatively, if you're using server-side rendering, you can
25-
send the polyfill bundle that's necessary for the browser making that request.
28+
If you are only targeting a specific browser, you can just use the bundle that's
29+
needed by it; alternatively, if your server is capable of serving different assets based on user agent, you can send the polyfill bundle that's necessary for the browser making that request.
2630

2731
## `webcomponents-loader.js`
2832

2933
Alternatively, this repo also comes with `webcomponents-loader.js`, a client-side
30-
loader that dynamically loads the correct polyfill bundle, using feature detection.
34+
loader that dynamically loads the minimum polyfill bundle, using feature detection.
3135
Note that because the bundle will be loaded asynchronously, you should wait for the `WebComponentsReady` before you can safely assume that all the polyfills have
3236
loaded and are ready to be used (i.e. if you want to dynamically load other custom
3337
elements, etc.). Here's an example:
3438

3539
```
36-
<head>
37-
<script src="bower_components/webcomponentsjs/webcomponents-loader.js"></script>
38-
<script>
39-
// When the polyfill has loaded, lazy-load another custom element (otherwise,
40-
// if we do this before CustomElements has loaded, the element registration
41-
// will fail.)
42-
window.addEventListener('WebComponentsReady', function() {
43-
var s = document.createElement('script');
44-
s.src = 'lazy-element.js';
45-
document.head.appendChild(s);
46-
});
47-
</script>
48-
</head>
40+
<!-- Load polyfills; note that "loader" will load these async -->
41+
<script src="bower_components/webcomponentsjs/webcomponents-loader.js"></script>
42+
43+
<!-- Load a custom element definition via HTMLImports -->
44+
<link rel="import" href="my-element.html">
45+
46+
<!-- Use the custom element -->
47+
<my-element></my-element>
48+
49+
<!-- Interact with the upgraded element -->
50+
<script>
51+
window.addEventListener('WebComponentsReady', function() {
52+
// At this point we are guaranteed that all required polyfills have loaded,
53+
// all HTML imports have loaded, and all defined custom elements have upgraded
54+
let MyElement = customElements.get('my-element');
55+
let element = document.querySelector('my-element');
56+
console.assert(element instanceof MyElement); // 👍
57+
element.someAPI(); // 👍
58+
});
59+
</script>
4960
```
5061

5162
## Browser Support

0 commit comments

Comments
 (0)