Problem
HTML has advanced in many ways over the last two decades, but it hasn’t grown much as a hypermedia. In particular, anchors and forms are still the primary way to drive network activity via user interactions in pure HTML-based applications.
Due to these limitations, javascript has come to the fore as the premier technology for building advanced web applications. Unfortunately, as a consequence, much of the original power and simplicity of the web is being lost. In particular, Hypermedia is no longer The Engine of Application State. Rather, application state is often maintained in in-memory javascript stores and the DOM is reactively updated based on that state.
A Potential Way Forward
I have been working on an open source javascript library for about a decade now that tries to address the shortcomings of HTML while still remaining firmly within the original, REST-ful model of the web. It began as intercooler.js and last summer was renamed to htmx, after I broke the dependency on jQuery.
The core idea is to use extended HTML attributes to drive server interactions, and allow for the replacement of elements within the DOM, rather than whole-page refreshes, based on HTML content returned from the server. This very much satisfies the REST constraints, and extends HTML as a hypertext (hence htmx).
htmx demonstrates that, with a few declarative HTML attributes, you can express many common UX patterns that would normally be done with javascript.
The most significant attributes are:
- hx-get, etc. - specifies the url to issue a request too
- hx-trigger - specifies the event that triggers a request
- hx-target - specifies the element to update in the DOM
- hx-swap - specifies the manner in which the returned HTML content should be swapped into the DOM
Here is an example that demonstrates the “Live Search” pattern, using only a few attributes:
https://htmx.org/examples/active-search/
Moving HTML Forward as a Hypertext
It seems to me that much of the functionality of htmx could, and perhaps should, simply be part of normal HTML. There is no reason a hypermedia should have to replace the entire document on navigation, and there is no reason why only clicks and submits should be able to drive network interactions.
The particulars of the htmx attributes don’t matter nearly as much as the general idea of revisiting HTML qua hypermedia and thinking about how we can drive it, and, therefore hypermedia-based application development, forward.