HTML Imports polyfill
npm install @webcomponents/html-importsA polyfill for HTMLImports.

The polyfill hosts the imported documents in the import link element. E.g.
``html
`
The polyfill fires the HTMLImportsLoaded event when imports are loaded, and exposes the HTMLImports.whenReady method. This api is necessary because unlike the native implementation, script elements do not force imports to resolve. Instead, users should wrap code in either an HTMLImportsLoaded handler or after load time in an HTMLImports.whenReady(callback) call.
The polyfill provides the HTMLImports.importForElement() method which can be used to retrieve the that imported an element.
The polyfill appends the imported contents to the itself to leverage the native implementation of Custom Elements, which expects scripts upgrading the CustomElementRegistry to be connected to the main document.
As a consequence, .ownerDocument will be the main document, while .parentNode of the imported children will be the itself. Consider using HTMLImports.importForElement() in these cases. e.g:
`javascript`
const ownerDoc = HTMLImports.importForElement(document.currentScript);
let someElement = ownerDoc.querySelector('some-element');
if (ownerDoc !== HTMLImports.importForElement(someElement)) {
// This element is contained in another import, skip.
someElement = null;
}
If you require document isolation, use html-imports#v0.
The polyfill supports dynamically added imports by observing mutations in
and within other imports; it won't detect imports appended in .If you require to append imports in
, notify the polyfill of these additions using the method HTMLImports.loadImports(document.body).$3
In IE/Edge, appending
in a node that is not breaks the cascading order; the polyfill checks if an import contains a , and moves all the imported and And is imported in index.html:
`html
`This is how the resolved import will look like:
`html
`The placeholders contain a reference to the applied element:
`javascript
var myImport = document.head.querySelector('link[rel=import]').import;
var link = myImport.querySelector('link');
console.log(link.__appliedElement || link);
var style = myImport.querySelector('style');
console.log(style.__appliedElement || style);
`Building & Running Tests
$3
`bash
$ git clone https://github.com/webcomponents/html-imports.git
$ cd html-imports
$ npm i
$ bower i
$ gulp
`$3
`bash
$ npm i -g web-component-tester
$ wct
``