30

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?

10
  • I didn't even know HTML imports was there in the first place... Commented Nov 8, 2018 at 19:47
  • 5
    yes, as I noted in my question I know I can use lit-html or other things, but the point of web-components is to NOT to have to use a library or framework to make them work, html imports worked fine for this without a library, and it seems like ES6 Modules should do the same, seems like tons of conversation on this years ago, then nothing.... Commented Nov 8, 2018 at 20:14
  • 1
    Also thanks for the extension suggestion, I found - ES6 String HTML - marketplace.visualstudio.com/…, it works great. Commented Nov 8, 2018 at 20:27
  • 1
    @Joelio the second link is exactly the same question. For your question in comments: there's still no consensus on it so it won't be implemented as a standard in a near future (1-2 years) Commented Nov 9, 2018 at 13:44
  • 2
    It's been a couple years. Any update on this? ES modules for importing html into html? Commented Aug 15, 2020 at 1:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.