Skip to content

Instantly share code, notes, and snippets.

@GitSquared
Last active January 22, 2021 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GitSquared/674263d4b7b36cd1b0eeb5bdf3160b99 to your computer and use it in GitHub Desktop.
Save GitSquared/674263d4b7b36cd1b0eeb5bdf3160b99 to your computer and use it in GitHub Desktop.
Simple HTML Import with custom element that replaces itself with imported content
<script>
window.customElements.define('get-import', class extends HTMLElement {
constructor() {
super();
if (this.hasAttribute('url'))
window.fetch(this.attributes.url.value)
.then(res => res.text())
.then(txt => this.outerHTML = txt);
}
});
</script>
<!-- This element will replace itself with the document specified in url attribute -->
<get-import url="folder/page.html"></get-import>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment