HTMX
Make web development simple and fun again
My opinionated Odyssey
…. finding a simple way to do web development
Start of Odyssey
1999: CGI Scripting with Shell and Perl
2001: Python
2006: No fancy JS, boring DB applications.
2008..today: Python and Django
Hypes of the past
Perl, Visual Basic, CORBA
XML+XSLT
Java Applets
Macromedia/Adobe Flash
More about this topic: Deadends of IT
2014: Angular
Wow, that’s the future: The server sends JSON to the browser.
Like “real” application.
But customers kept us busy doing the things we did before (Django with some jQuery)
JSON = Clean
HTML = Dirty
2020: React / Vue
I played with React.
React ... like in-browser PHP
Vue is nice ...
Great for native App…
But, I don’t want a native App. First endpoint in DRF, then FE … grrr
2021 Small project from scratch
Spare-time vs Business Context.
Reduce Cognitive Load
Spare-time Project:
Too many options!
Analysis Paralysis
→ make list/spreadsheet of options.
I don’t get paid by the hour
Frontend Blues
... But I still haven't found what I'm looking for ...
Om - What do I like?
What do I want to improve?
One Page, several Parts
Part 1
Part 2
Part 3
I want to update each part on its own
Part 1
Part 2
Part 3
GET https://example.com/news
PUT https://example.com/chat
POST https://example.com/foo-form
SPA ?
Single Page Application?
….. no, not needed.
I just want to Submit/Reload parts of the page.
Form Validation in the Browser?
nice to have validation on the client side …. but
but I need to validate on server, too.
html5 has some fine stuff
I don’t need JS based form validation on the client side now (maybe later)
Write everything in JS to re-use three lines of code?
SSR Hype
Is there no alternative?
JSON HTML Fragments over the wire
_! Revolution !_
HTMX
FrOW: Which Lib?
One Page, several Parts
Part 1
Part 2
Part 3
Partial Page Updates with HTMX
….
<button
hx-get=”URL"
hx-swap="outerHTML">
Press me
</button>
….
….
<div>Simple div</div>
….
<div>Simple div</div>
Response from URL:
HTML Fragments over the wire
HTMX is declarative like ...
like HTML
like CSS
like SQL
like Django admin.py
like Terraform
like K8s manifest
…. nice!
HTMX
Separation of Concerns
Locality of Behaviour
Django
My Naming Pattern
Django Function based views:
foo_page(request, ...) → returns page response. URL: /foo
foo_hx(request, ...) → returns fragment response. URL: /foo_hx
foo_html(...) → returns HTML SafeString (for internal re-use)
HTMX is great for:
NOT:
Rethinking “Smart” re-use of API?
JSON
HTML
SQL
Serve the matching format
gRPC (JSON)
HTML
Stable API
Improve daily, A/B Testing
SQL
End of Odyssey?
It is just the beginning :-)
Example Project
Thomas Güttler, June 2021
Thank you for listening.
Feedback is welcome!