htmx - chemnitzer linux-tage 2021

31
HTMX Make web development simple and fun again

Upload: others

Post on 21-May-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: HTMX - Chemnitzer Linux-Tage 2021

HTMX

Make web development simple and fun again

Page 2: HTMX - Chemnitzer Linux-Tage 2021

My opinionated Odyssey

Page 3: HTMX - Chemnitzer Linux-Tage 2021

History

1999: CGI Scripting with Shell and Perl

2001: Python

2008..today: Python and Django

Page 4: HTMX - Chemnitzer Linux-Tage 2021

2014: Angular

Wow, that’s the future: The server sends JSON to the browser.

But customers kept us busy doing the things we did before (Django)

Page 5: HTMX - Chemnitzer Linux-Tage 2021

2020: React / Vue

I am glad, that I sticked to Django,

and did not chose Angular.

I played with React/Vue … but no “wow”

Page 6: HTMX - Chemnitzer Linux-Tage 2021

Om - What do I like?

● I like the Django Forms library○ Create HTML (on the server)○ Validate user input (on the server)

● I like Django ORM● HTTP & HTML

Page 7: HTMX - Chemnitzer Linux-Tage 2021

What do I want to improve?

● Full Page Reload after sending a form. Grrrr● Own ajax library for submitting/reloading snippets: No fun.

Page 8: HTMX - Chemnitzer Linux-Tage 2021

One Page, several Parts

Part 1

Part 2

Part 3

Page 9: HTMX - Chemnitzer Linux-Tage 2021

Part 1

Part 2

Part 3

GET https://example.com/news

PUT https://example.com/chat

POST https://example.com/foo-form

Page 10: HTMX - Chemnitzer Linux-Tage 2021

SPA ?

Single Page Application?

….. no, not needed.

I just want to Submit/Reload parts of the page.

Page 11: HTMX - Chemnitzer Linux-Tage 2021

State-Management

● State?● Stateless has won:

○ CORBA → http○ Server with long uptime → Container

● I don’t want a valuable state on the client. Only GUI state (scrolling, folding)● Every valuable state should be in the central database.

Page 12: HTMX - Chemnitzer Linux-Tage 2021

Form Validation in the Browser?

….. ok, nice to have validation on the client side …. but

…. but I need to validate on server, too.

Maybe I don’t need validation on the client side?

Page 13: HTMX - Chemnitzer Linux-Tage 2021

SSR Hype

● Looked at Server-Side-Rendering of React/Vue● wait ! ! !● This huge stack ....● Do really want that?● Are there alternatives?

If you prefer boring facts to emotions: Rendering on the Web

Page 14: HTMX - Chemnitzer Linux-Tage 2021

Declarativevs

Imperative

Page 15: HTMX - Chemnitzer Linux-Tage 2021

HTML, CSS, SQLvs

if/else, loops ...

Page 16: HTMX - Chemnitzer Linux-Tage 2021

Conditionless 💕

Page 17: HTMX - Chemnitzer Linux-Tage 2021

HTML 💕

Page 18: HTMX - Chemnitzer Linux-Tage 2021

Keep the Client ...

Simple & Stateless

Page 19: HTMX - Chemnitzer Linux-Tage 2021

JSON HTML Fragments over the wire

● Unpoly: unpoly.com● Hotwire: hotwire.dev● …● HTMX: htmx.org

Page 20: HTMX - Chemnitzer Linux-Tage 2021

HTMX adds new Attributes

<button hx-post="/clicked" hx-swap="outerHTML">

Click Me

</button>

Page 21: HTMX - Chemnitzer Linux-Tage 2021

HTML Fragments over the wire

URL /clicked

→ HTML Fragment/Snippet from server to client.

Page 22: HTMX - Chemnitzer Linux-Tage 2021

HTMX

● Works with every language (server side)

● ~9k min.gz

Page 23: HTMX - Chemnitzer Linux-Tage 2021

hx-trigger

<div hx-get="/clicked" hx-trigger="click">

Click Me

</div>

hx-trigger docsload, revealed, every 1s

Page 25: HTMX - Chemnitzer Linux-Tage 2021

HTMX

Hyperscript

Page 26: HTMX - Chemnitzer Linux-Tage 2021

You might not need JQuery?

We enjoy typing ???http://youmightnotneedjquery.com/

Page 27: HTMX - Chemnitzer Linux-Tage 2021

Hyperscript

Hyperscript is a fun little scripting language for doing front end web development.

hyperscript.org

Page 28: HTMX - Chemnitzer Linux-Tage 2021

Hyperscript: Step by Step

<button _="on click put 'I was clicked!' into my.innerHTML">

Click Me!

</button>

No Async, No Await, No Promises

Page 29: HTMX - Chemnitzer Linux-Tage 2021

You might not need JS

Page 30: HTMX - Chemnitzer Linux-Tage 2021

End of Odyssey?

Page 31: HTMX - Chemnitzer Linux-Tage 2021

HTMX + Hyperscript💕

Make web development simple and fun again

Thomas Güttler, March 2021