webcomponentsjs 0,0,6,0,5,5,4,0 Bower npm

A suite of polyfills supporting the HTML Web Components specs

webcomponents.js (v1 spec polyfills)

Build Status

Note. For polyfills that work with the older Custom Elements and Shadow DOM v0 specs, see the v0 branch.

A suite of polyfills supporting the Web Components specs:

  • Custom Elements v1: allows authors to define their own custom tags (spec, tutorial).
  • HTML Imports: a way to include and reuse HTML documents via other HTML documents (spec, tutorial).
  • Shadow DOM v1: provides encapsulation by hiding DOM subtrees under shadow roots (spec, tutorial).

For browsers that need it, there are also some minor polyfills included: - HTMLTemplateElement - Promise - Event, CustomEvent, MouseEvent constructors and Object.assign, Array.from (see webcomponents-platform)

How to use

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

  • webcomponents-hi.js – HTML Imports (needed by Safari Tech Preview)
  • webcomponents-hi-ce.js – HTML Imports and Custom Elements v1 (needed by Safari 10)
  • webcomponents-hi-sd-ce.js – HTML Imports, Custom Elements v1 and Shady DOM/CSS (needed by Safari 9, Firefox, Edge)
  • webcomponents-sd-ce.js – Custom Elements and Shady DOM/CSS (no HTML Imports)
  • 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)

If you are only targeting a specific browser, you can just use the bundle that’s 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.

webcomponents-loader.js

Alternatively, this repo also comes with webcomponents-loader.js, a client-side loader that dynamically loads the minimum polyfill bundle, using feature detection. 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 loaded and are ready to be used (i.e. if you want to dynamically load other custom elements, etc.).

Additionally, you can check if window.WebComponents exists to know if the WebComponentsReady event will fire, and you can check if window.WebComponents.ready is true to check if the WebComponentsReady event has already fired.

Here’s an example:

”`html