logoalt Hacker News

HumanOstrich05/04/20252 repliesview on HN

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`.

Replies

librasteve05/04/2025

this here is the main idea of HTMX - extended to work for any tag p, div, content, aside …

there are many examples of HTMX (since it is a self contained and tiny) being used alongside existing frameworks

of course for some of us, since HTMX brings dynamic UX to back end frameworks, it is a way of life https://harcstack.org (warning - raku code may hurt your eyes)

show 1 reply
johnisgood05/04/2025

But this requires JavaScript...

show 2 replies