logoalt Hacker News

matchagaucho05/03/20252 repliesview on HN

I've become a fan of https://htmx.org for this reason.

A small 10KB lib that augments HTML with the essential good stuff (like dynamic imports of static HTML)


Replies

HumanOstrich05/04/2025

Seems like overkill to bring in a framework just for inlining some static html. If that's all you're doing, a self-replacing script tag is neat:

    <script>
      function includeHTML(url) {
        const s = document.currentScript
        fetch(url).then(r => r.text()).then(h => {
          s.insertAdjacentHTML('beforebegin', h)
          s.remove()
        })
      }
    </script>
...

    <script>
      includeHTML('/footer.html')
    </script>
The `script` element is replaced with the html from `/footer.html`.
show 2 replies
gforce_de05/04/2025

The minified version needs ~51 kilobytes (16 compressed):

  $ curl --location --silent "https://unpkg.com/[email protected]" | wc -c
  50917
  
  $ curl --location --silent "https://unpkg.com/[email protected]" | gzip --best --stdout | wc -c
  16314
show 1 reply