(bits of) JavaScript, Java, C, C++, Clojure, PHP, Ruby... Founder and CEO (+ acting CTO) of Abilian since 2012 Free/Open source user since 1988 (Nethack) Linux user since 1991 htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 2
15kB (compressed) JavaScript library, no dependencies Created by Carson Gross in 2020 (Rewrite of Intercooler, started in 2014) Helps implement hypermedia-driven applications (HDA), htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 3
Hypermedia to back again. 2. Hypermedia and htmx 1. Hypermedia fundamentals. 2. htmx: the missing pieces to the current web. 3. Using htmx 1. Front-end (HTML) patterns 2. Server patterns 4. htmx in practice. 1. Case studies 2. Scaling htmx. 5. Conclusion htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 6
ActiveX, Java applets, Flash, Silverlight App vs. website divide CSS and JS in their primitive stages XMLHttpRequest for HTML or XML exchange htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 9
web frameworks now push JSON to the browsers (e.g. DRF, Flask-Rest*, etc.) + New frameworks focused on JSON APIs: FastAPI, Sanic, Litestar... Server frameworks adapting to "HTML for apps" approach Rise of Blazor, Phoenix LiveView, Livewire, htmx... Innovations and complexities introduced by SPAs. => Seeking the balance of flexibility and simplicity. htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 12
to the RESTful network architecture in Fielding’s original sense of this term, and in particular to the HATEOAS (Hypermedia as the engine of application state) principles. NB: “REST” shouldn't be confused with "JSON APIs". JSON is not a natural hypermedia due to the absence of hypermedia controls. The exchange of hypermedia is (according to Gross) an explicit requirement for a system to be considered “RESTful.” htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 14
and <form> be able to make HTTP requests? Why should only click & submit events trigger them? Why should only GET & POST methods be available? Why should you only be able to replace the entire screen? htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 15
able to make HTTP requests hx-get , hx-post , hx-put , hx-patch , hx-delete Any event should be able to trigger an HTTP request hx-trigger Any HTTP Action should be available hx-put , hx-patch , hx-delete Any place on the page should be replaceable hx-target , hx-swap htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 16
elegantly and without demanding developers write JavaScript code. htmx & Hypermedia apps @ OSXP 2023 htmx gives access to "AJAX", CSS Transitions, browser history, WebSockets and Server Sent Events directly in HTML, using only attributes, so you can build modern user interfaces ("SPA- like") with the simplicity and power of hypertext “ “ S. Fermigier / Abilian 17
tags to use AJAX instead. It works even with JavaScript disabled. <div hx-boost="true"> <a href="/page1">Go To Page 1</a> <a href="/page2">Go To Page 2</a> </div> <!-- or --> <form hx-boost="true" action="/example" method="post"> <input name="email" type="email" placeholder="Enter email..."> <button>Submit</button> </form> htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 20
The Contacts </button> </div> hx-get — send GET request to the provided URL hx-post — send POST request to the provided URL hx-put — send PUT request to the provided URL hx-patch — send PATCH request to the provided URL hx-delete — send DELETE request to the provided URL htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 21
change the behavior of the trigger, including: once — ensures a request will only happen once changed — issues a request if the value of the HTML element has changed delay:<time interval> — waits for the given amount of time before issuing the request from:<CSS Selector> — listens for the event on a different element ... htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 23
principle. Splitting the templates should be done a a way the respects this principle. Some patterns have emerged (see, e.g., Django htmx patterns) but rely on specifics features of templates languages or extensions. (No time to discuss today), htmx & Hypermedia apps @ OSXP 2023 The behaviour of a unit of code should be as obvious as possible by looking only at that unit of code “ “ S. Fermigier / Abilian 28
21K LOC code base) No reduction in the application’s UX Reduced the overall code base size by 67% Increased python code by 140% (500 LOC to 1200 LOC) - a good think if you like Python First load time-to-interactive reduced by 50-60% Handles much larger data sets (react simply couldn’t handle the data) Web application memory usage was reduced by 46% (75MB to 45MB) htmx & Hypermedia apps @ OSXP 2023 31
to 12044 LOC) Subjectively, development velocity felt at least 5X faster Rather than prototyping in Figma and then porting to HTML, UX development was done directly in HTML Source: Linkedin post Code base (before/after): https://github.com/OpenUnited/ htmx & Hypermedia apps @ OSXP 2023 32
rewrite of older jQuery- and Vue-based projects Demos on https://github.com/sfermigier/demos webbits: an open source component framework and library for Python & htmx (ongoing project) htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 33
Low-Interactivity Sites: Best for text and image-based sites (e.g., Amazon, eBay, news sites). Server-Side Value Addition: Great for applications relying on server-side processing and data analysis. Large-Grain Data Transfers: All applications which use anchor tags and forms, with responses that return entire HTML documents from requests. Wide Application Range: Suitable for a variety of applications, extending beyond basic content display sites. Simplifies Client-Side Complexity: Reduces the need for client-side routing, state management, and JavaScript logic. htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 34
online spreadsheets (where updates trigger cascading changes), games... Performance Concerns: Hypermedia can reduce performance in situations requiring rapid, dynamic updates on user interactions. Complex User Interface Dynamics: Ineffective for interfaces without clear update boundaries, needing continuous data refresh. Avoid for Large-Grain Data Inefficiency: Not ideal for applications where the "large-grain hypermedia data transfer" model is too coarse. Use Case for Sophisticated Client-Side JavaScript: Better to use advanced client-side JavaScript for complex, interactive elements. htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 35
to provide (presumably lightweight) interactivity on the client (ex: hamburger menus, rich- text editors, complex data-grid, image editor...) in a context of an HDA / MPA, htmx-based (or not), application. A DX issue can be the confusion that can appear from mixing 2 different template languages (e.g. Jinja and Vue or Alpine). AlpineJS or Web Components are approaches that can be seen in the wild (and that I have personally experimented). htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 36
The prime directive of an HDA is to use Hypermedia As The Engine of Application State. A hypermedia-friendly scripting approach will follow this directive. “ “ Practically, this means that scripting should avoid making non- hypermedia exchanges over the network with a server. “ “ hypermedia-friendly scripting should avoid the use of fetch() and XMLHttpRequest unless the responses from the server use a hypermedia of some sort ( e.g. HTML), rather than a data API format ( e.g. plain JSON). “ “ 38
be beneficial for simpler parts of an app, like settings pages with straightforward forms. Manage Your Complexity Budget: Reserve hypermedia for simpler application aspects, allocating more complexity to critical, intricate functionalities. htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 39
for large projects Scaling? = handling more nodes, requests, features, complexity, and team size The Web as the most successful and large scale distributed system Hypermedia's role in the Web's scalability Importance to individual developers htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 41
should be stateless Software should support horizontal scaling Features in the software should be independent The performance of the system should be observable The software should utilize caching HDA ticks all the boxes htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 42
and client-side deep features HDAs are well suited for server-side complex features HDAs are less suited for client-side intense UI interactions In which case the architecture should enable integrating complex front-end behavior developped using client-side technologies (JavaScript, WASM...) htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 44
developers needed Elimination of front-end/back-end split Preference for smaller, more efficient teams But larger teams should be OK too htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 45
"Learn how hypermedia, the revolutionary idea that created The Web, can be used today to build modern, sophisticated web applications, often at a fraction of the complexity of popular JavaScript frameworks." Freely available on https://hypermedia.systems/ htmx & Hypermedia apps @ OSXP 2023 47
In many cases, htmx is a viable alternative to SPAs. It balances performance, simplicity, and scalability. Future prospects for htmx and hypermedia in large-scale projects. htmx & Hypermedia apps @ OSXP 2023 S. Fermigier / Abilian 51
presentation is derived from the htmx.org and hypermedia.systems websites. Errors are mine. Contact: [email protected] / https://abilian.com/ [email protected] / https://fermigier.com/ Slides created with MARP. htmx & Hypermedia apps @ OSXP 2023 52