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

Commit 1d03bdb

Browse files
authored
Merge pull request #693 from webcomponents/words-about-the-loader
Use better words about the bundles and the loader
2 parents f35acf8 + a063ae3 commit 1d03bdb

1 file changed

Lines changed: 52 additions & 14 deletions

File tree

README.md

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,65 @@ webcomponents.js
33

44
[![Build Status](https://travis-ci.org/webcomponents/webcomponentsjs.svg?branch=master)](https://travis-ci.org/webcomponents/webcomponentsjs)
55

6-
A suite of polyfills supporting the [Web Components](http://webcomponents.org) specs.
6+
A suite of polyfills supporting the [Web Components](http://webcomponents.org) specs:
77

88
- **Custom Elements**: allows authors to define their own custom tags ([spec](https://w3c.github.io/webcomponents/spec/custom/)).
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-
## Releases
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))
1316

14-
Pre-built (concatenated & minified) versions of the polyfills are maintained in the [tagged versions](https://github.com/webcomponents/webcomponentsjs/releases) of this repo. There are several variants:
17+
## How to use
1518

16-
- `webcomponents-lite.js` includes all of the polyfills.
17-
- `webcomponents-loader.js` is a custom loader that dynamically load a minified polyfill
18-
bundle, using feature detection. The bundles that can be loaded are:
19-
- `webcomponents-hi` -- HTML Imports (needed by Safari Tech Preview)
20-
- `webcomponents-hi-ce` -- HTML Imports and Custom Elements (needed by Safari 10)
21-
- `webcomponents-hi-ce-sd` -- HTML Imports, Custom Elements and Shady DOM/CSS (needed by Safari 9, Firefox, Edge)
22-
- `webcomponents-lite` -- HTML Imports, Custom Elements, Shady DOM/CSS and generic platform polyfills (such as Template, ES6 Promise, Constructable events, etc.) (needed by Internet Explorer 11)
19+
The polyfills are built (concatenated & minified) into several bundles that target
20+
different browsers and spec readiness:
21+
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)
27+
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.
30+
31+
## `webcomponents-loader.js`
32+
33+
Alternatively, this repo also comes with `webcomponents-loader.js`, a client-side
34+
loader that dynamically loads the minimum polyfill bundle, using feature detection.
35+
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
36+
loaded and are ready to be used (i.e. if you want to dynamically load other custom
37+
elements, etc.). Here's an example:
38+
39+
```
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>
60+
```
2361

2462
## Browser Support
2563

26-
Our polyfills are intended to work in the latest versions of evergreen browsers. See below
64+
The polyfills are intended to work in the latest versions of evergreen browsers. See below
2765
for our complete browser support matrix:
2866

2967
| Polyfill | IE11+ | Chrome* | Firefox* | Safari 9+* | Chrome Android* | Mobile Safari* |
@@ -34,13 +72,13 @@ for our complete browser support matrix:
3472

3573
\*Indicates the current version of the browser
3674

37-
The polyfills may work in older browsers, however require additional polyfills (such as classList)
38-
to be used. We cannot guarantee support for browsers outside of our compatibility matrix.
75+
The polyfills may work in older browsers, however require additional polyfills (such as classList, or other [platform](https://github.com/webcomponents/webcomponents-platform)
76+
polyfills) to be used. We cannot guarantee support for browsers outside of our compatibility matrix.
3977

4078

4179
### Manually Building
4280

43-
If you wish to build the polyfills yourself, you'll need `node` and `npm` on your system:
81+
If you wish to build the bundles yourself, you'll need `node` and `npm` on your system:
4482

4583
* install [node.js](http://nodejs.org/) using the instructions on their website
4684
* use `npm` to install [gulp.js](http://gulpjs.com/): `npm install -g gulp`

0 commit comments

Comments
 (0)