logoalt Hacker News

Kuyawa05/05/20250 repliesview on HN

Or this:

  <body>
    <include src="header.html"></include>
    <main>
      <h1>Hello includes</h1>
    </main>
    <include src="footer.html"></include>
  </body>
  <script>
  (async function include(){
    const objs = document.getElementsByTagName('include')
    const tags = Array.from(objs)
    for(tag of tags){
      const src  = tag.getAttribute('src')
      const data = await fetch(src)
      const html = await data.text()
      tag.outerHTML = html
    }
  })()
  </script>
* beware autoclosing tags won't work