top | item 43882942

(no title)

matchagaucho | 10 months ago

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)

discuss

order

HumanOstrich|10 months ago

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

librasteve|10 months ago

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)

johnisgood|10 months ago

But this requires JavaScript...

gforce_de|10 months ago

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

  $ curl --location --silent "https://unpkg.com/htmx.org@2.0.4" | wc -c
  50917
  
  $ curl --location --silent "https://unpkg.com/htmx.org@2.0.4" | gzip --best --stdout | wc -c
  16314