Is there a way to use es6 modules to import html template into javascript?

8.9k views Asked by At

There seems to be many dated questions on this topic, I cant find one more recent (2018). Also other questions just focus on getting this to work, I am focused on the right path forward for making this work following the path of ES6 Modules with regards to HTML Imports.

All the browsers seem to agree that html import is dead

 <link rel="import" href="https://xyz.html">

If this is true, is there a good way to import an html

<template>

for use in JavaScript?

I found this trick here - Create and Use a Custom HTML Component? , but it relies on the HTML being in the JavaScript file as a string.

In my perfect world, I could define an HTML file template.html (so I get nice editor color coding), but be able to import that for use in my dom.

I know there are libraries like lit-html that make this easy, but it seems since ES6 modules are standard now, and since html imports were deprecated in lieu of ES6 modules, that there should be some simple native way to do this?

0

There are 0 answers