4

I have a few html imports, which I use to load some reusable html fragments (not necessarily html templates), below is a minimalistic example of its usage. Given Html imports are becoming obsolete in Chrome could anyone come up with an equivalent module based implementation?

<!DOCTYPE html>
<html>

<head>
  <link rel="import" name="ImportName" href="...">
</head>

<body>
  <textarea id="textarea"></textarea>
  <script>
    document.getElementById("textarea").value = document.querySelector("link[name='ImportName']").import.body.innerHTML;
  </script>
</body>

</html>
JsCoder
  • 117
  • 1
  • 9
  • Possible duplicate of [If HTML Imports are dead/deprecated what's the best way to import your web component (X-Tag) template?](https://stackoverflow.com/questions/37345522/if-html-imports-are-dead-deprecated-whats-the-best-way-to-import-your-web-compo) – Harry May 14 '19 at 14:04
  • Unfortunately flagged as duplicate: https://stackoverflow.com/questions/37345522/if-html-imports-are-dead-deprecated-whats-the-best-way-to-import-your-web-compo – Harry May 14 '19 at 14:05
  • 2
    [Chris Coyier recently published an article covering several ways to handle this.](https://css-tricks.com/the-simplest-ways-to-handle-html-includes/) – Alexander Nied May 14 '19 at 14:17
  • @AlexanderNied this might work, thanks! – JsCoder May 15 '19 at 07:36
  • Does this answer your question? [How to separate web components to individual files and load them?](https://stackoverflow.com/questions/55080103/how-to-separate-web-components-to-individual-files-and-load-them) – Michael Freidgeim Jul 16 '20 at 20:32

0 Answers0