According to MDN the HTML import feature is not supported by Firefox and has to be considered obsolete since Chrome 73 (don't care about other browsers and neither about older versions of Chrome and Firefox).
I'd like to try out web components. I currently have:
- a Javascript file defining my class that extends an
HTMLElement
- an HTML file containing a
<template>
for my component
How am I supposed to bundle the two pieces and reuse them on different HTML pages?
Since I cannot import HTML, I suppose the only thing left is to import a Javascript. However, I'm not sure about how deal with it.
I know I can use document.createElement()
in my Javascript, and create my template programmatically, but I would like to avoid it, if possible. Writing Javascript to get HTML seems stupid to me, unless there is a valid reason to do otherwise.
Another option I see is to write my HTML template as the innerHTML
of some node I create in my Javascript. But it does not sound so clean.
Am I missing something? Which is the recommended way to import web components?
Thanks in advance