Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@webcomponents/html-imports
Advanced tools
A polyfill for HTMLImports.
The polyfill hosts the imported documents in the import link element. E.g.
<link rel="import" href="my-element.html">
<!-- becomes -->
<link rel="import" href="my-element.html">
<!-- my-element.html contents -->
</link>
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 <link rel=import>
that imported an element.
<link>.import
is not a Document
The polyfill appends the imported contents to the <link>
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 <link rel=import>
itself. Consider using HTMLImports.importForElement()
in these cases. e.g:
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 <head>
and within other imports; it won't detect imports appended in <body>
.
If you require to append imports in <body>
, notify the polyfill of these additions using the method HTMLImports.loadImports(document.body)
.
In IE/Edge, appending <link rel=stylesheet>
in a node that is not <head>
breaks the cascading order; the polyfill checks if an import contains a <link rel=stylesheet>
, and moves all the imported <link rel=stylesheet>
and <style>
to <head>
. It drops a placeholder element in their original place and assigns a reference to the applied element, placeholder.__appliedElement
. e.g.
my-element.html
imports a stylesheet and applies a style:
<link rel="stylesheet" href="my-linked-style.css" />
<style>
.blue {
color: blue;
}
</style>
And is imported in index.html:
<head>
<link rel="import" href="my-element.html" />
</head>
This is how the resolved import will look like:
<head>
<link rel="stylesheet" href="my-linked-style.css">
<style> .blue { color: blue }; </style>
<link rel="import" href="my-element.html">
<link type="import-placeholder">
<style type="import-placeholder"></style>
</link>
</head>
The placeholders contain a reference to the applied element:
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);
$ git clone https://github.com/webcomponents/html-imports.git
$ cd html-imports
$ npm i
$ bower i
$ gulp
$ npm i -g web-component-tester
$ wct
FAQs
HTML Imports polyfill
We found that @webcomponents/html-imports demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.