WEBVTT

00:00:00.000 --> 00:00:03.180
So I recently released a brand new

00:00:03.180 --> 00:00:06.720
course, "HTMX - The Practical Guide".

00:00:07.800 --> 00:00:11.440
That's a course I actually didn't plan to

00:00:11.440 --> 00:00:13.900
create, because I got plenty of work to

00:00:13.900 --> 00:00:16.940
do with an ongoing Next.js course

00:00:16.940 --> 00:00:19.660
update and an ongoing Angular course

00:00:19.660 --> 00:00:22.380
update, and both updates will be

00:00:22.380 --> 00:00:22.760
amazing.

00:00:22.980 --> 00:00:24.540
I'm working on them, but they will still

00:00:24.540 --> 00:00:25.340
take some time.

00:00:26.240 --> 00:00:27.900
I get some other work and some other

00:00:27.900 --> 00:00:29.700
course related work as well.

00:00:29.920 --> 00:00:33.960
So HTMX was originally not a topic I

00:00:33.960 --> 00:00:37.800
planned on covering with a course, but

00:00:37.800 --> 00:00:42.740
then I worked with HTMX quite a bit over

00:00:42.740 --> 00:00:44.340
the last couple of months.

00:00:44.760 --> 00:00:48.040
And I have to say, it's really an amazing

00:00:48.040 --> 00:00:49.780
JavaScript library.

00:00:50.100 --> 00:00:52.140
And you might, of course, wonder if you

00:00:52.140 --> 00:00:55.000
haven't heard about HTMX, do we really

00:00:55.000 --> 00:00:56.060
need another library?

00:00:56.320 --> 00:00:57.240
What does it do?

00:00:57.320 --> 00:00:58.340
What the others don't?

00:00:58.580 --> 00:01:03.660
The answer is HTMX helps you avoid

00:01:03.660 --> 00:01:06.700
writing front-end JavaScript code.

00:01:06.900 --> 00:01:10.280
You can still use it with front-end

00:01:10.280 --> 00:01:12.440
JavaScript code, and I do cover that in

00:01:12.440 --> 00:01:14.720
the course as well, but you don't have to.

00:01:14.940 --> 00:01:18.100
And at least in my experience, you often

00:01:18.100 --> 00:01:21.700
end up with websites, with web

00:01:21.700 --> 00:01:24.920
applications that have a way simpler

00:01:24.920 --> 00:01:28.620
front-end code structure than you would

00:01:28.620 --> 00:01:30.440
have with React and so on.

00:01:30.740 --> 00:01:33.760
Now, I'm also not saying that it's better

00:01:33.760 --> 00:01:35.820
than React, that it should always be

00:01:35.820 --> 00:01:37.300
used instead of React.

00:01:37.900 --> 00:01:40.480
Instead, both are amazing libraries.

00:01:40.660 --> 00:01:42.140
And of course, the same is true for

00:01:42.140 --> 00:01:43.120
Angular and so on.

00:01:43.340 --> 00:01:47.300
But for, at least in my experience, quite a

00:01:47.300 --> 00:01:49.960
few web applications and websites,

00:01:51.080 --> 00:01:54.080
HTMX might be the simpler solution, to

00:01:54.080 --> 00:01:54.580
be honest.

00:01:55.000 --> 00:01:58.020
Now, what exactly is HTMX though?

00:01:58.340 --> 00:01:59.140
What does it do?

00:01:59.420 --> 00:02:00.340
How does it work?

00:02:00.700 --> 00:02:03.000
As the name suggests, the idea is

00:02:03.000 --> 00:02:06.480
essentially that it extends the HTML

00:02:06.480 --> 00:02:07.780
markup language.

00:02:08.139 --> 00:02:11.360
It extends it by giving you a bunch of

00:02:11.360 --> 00:02:14.380
new attributes, which you can add to

00:02:14.380 --> 00:02:16.000
HTML elements.

00:02:16.300 --> 00:02:18.780
Now, what do these attributes do

00:02:18.780 --> 00:02:19.080
though?

00:02:19.720 --> 00:02:23.000
Well, in the end, they deal with sending

00:02:23.000 --> 00:02:24.340
AJAX requests.

00:02:24.840 --> 00:02:28.060
So, behind-the requests from the

00:02:28.060 --> 00:02:29.480
front-end to some back-end.

00:02:29.900 --> 00:02:33.780
And they, or HTMX as a library, then also

00:02:33.780 --> 00:02:38.100
deals with the response that's sent back.

00:02:38.400 --> 00:02:40.460
And HTMX makes sure that your

00:02:40.460 --> 00:02:44.540
front-end UI, your DOM, is updated with

00:02:44.540 --> 00:02:46.140
that response data.

00:02:46.500 --> 00:02:49.180
Though that data part is now also

00:02:49.180 --> 00:02:50.800
special and interesting.

00:02:51.600 --> 00:02:55.260
Because the idea with HTMX is that,

00:02:55.940 --> 00:02:58.920
unlike with React or Angular and so on,

00:02:59.400 --> 00:03:01.680
you're not exchanging JSON data

00:03:01.680 --> 00:03:03.580
between the front-end and the

00:03:03.580 --> 00:03:03.980
back-end.

00:03:04.240 --> 00:03:07.400
But instead, the idea is that your

00:03:07.400 --> 00:03:11.520
back-end prepares the HTML code that

00:03:11.520 --> 00:03:13.880
should be rendered on the screen.

00:03:14.720 --> 00:03:17.040
And that could be an entire page or just

00:03:17.040 --> 00:03:18.400
a snippet, just a fragment.

00:03:19.040 --> 00:03:21.840
And HTMX then makes sure that that

00:03:21.840 --> 00:03:25.540
response HTML code is inserted in the

00:03:25.540 --> 00:03:27.860
right place in the DOM.

00:03:28.100 --> 00:03:30.320
So, in the website the user sees.

00:03:30.800 --> 00:03:33.920
And you control where exactly that

00:03:33.920 --> 00:03:36.600
response HTML code will be inserted.

00:03:36.840 --> 00:03:40.040
And how it will be inserted with special

00:03:40.040 --> 00:03:43.800
attributes, special HTMX attributes that

00:03:43.800 --> 00:03:45.000
you can add to elements.

00:03:45.240 --> 00:03:48.200
So that you could use these HTMX

00:03:48.200 --> 00:03:51.840
attributes to make sure that when a

00:03:51.840 --> 00:03:54.200
form is submitted, a POST request is

00:03:54.200 --> 00:03:57.280
sent to a certain route, and the response

00:03:57.280 --> 00:04:00.580
HTML code that is sent back is then

00:04:00.580 --> 00:04:03.600
inserted in a specific place in the

00:04:03.600 --> 00:04:05.540
currently visible page.

00:04:05.860 --> 00:04:07.800
That's the idea with HTMX.

00:04:07.880 --> 00:04:09.440
And you don't need to write any

00:04:09.440 --> 00:04:11.780
JavaScript code for setting up the

00:04:11.780 --> 00:04:13.800
request, for sending the request, for

00:04:13.800 --> 00:04:16.060
preparing the data, for using the

00:04:16.060 --> 00:04:18.620
response data and for updating the

00:04:18.620 --> 00:04:18.839
DOM.

00:04:19.160 --> 00:04:20.980
You don't need to do any of that.

00:04:21.600 --> 00:04:23.400
HTMX does it for you.

00:04:23.520 --> 00:04:24.880
That's the main idea.

00:04:25.900 --> 00:04:29.840
Now, of course, since HTMX essentially

00:04:29.840 --> 00:04:33.220
needs a back-end that sends back HTML

00:04:33.220 --> 00:04:36.840
snippets or documents instead of JSON

00:04:36.840 --> 00:04:42.200
data, you can really only use HTMX if you

00:04:42.200 --> 00:04:44.700
own the back-end, if you're building a

00:04:44.700 --> 00:04:46.440
full-stack application in the end.

00:04:46.660 --> 00:04:49.500
Because only then can you make sure

00:04:49.500 --> 00:04:53.480
that it is such HTML data that's sent

00:04:53.480 --> 00:04:55.340
back instead of JSON data.

00:04:56.040 --> 00:04:59.660
So that is essentially a requirement, you

00:04:59.660 --> 00:05:00.200
could say.

00:05:00.280 --> 00:05:03.000
And that, of course, also means that if

00:05:03.000 --> 00:05:05.160
you're maybe building a back-end that's

00:05:05.160 --> 00:05:07.820
not just meant to be used by a web

00:05:07.820 --> 00:05:11.320
front-end, but also by a mobile app, for

00:05:11.320 --> 00:05:14.940
example, you might think twice whether

00:05:14.940 --> 00:05:17.640
you really want to use HTMX or not,

00:05:17.720 --> 00:05:20.480
because you might need to send JSON

00:05:20.480 --> 00:05:24.520
data to the mobile app and HTML data

00:05:24.520 --> 00:05:26.820
to the web app if it uses HTMX.

00:05:27.440 --> 00:05:29.680
And maintaining these two different

00:05:29.680 --> 00:05:32.500
APIs or these different sets of API

00:05:32.500 --> 00:05:35.280
endpoints might not be something you

00:05:35.280 --> 00:05:35.760
want to do.

00:05:36.400 --> 00:05:38.600
In addition, if you're building a super

00:05:38.600 --> 00:05:42.380
complex web user interface with a lot of

00:05:42.380 --> 00:05:44.320
interactivity, if you're building something

00:05:44.320 --> 00:05:47.300
like Google Docs or anything like that,

00:05:48.020 --> 00:05:51.120
you also might still want a library or

00:05:51.120 --> 00:05:53.380
framework like React or Angular

00:05:53.520 --> 00:05:57.100
because you have a lot of DOM updating

00:05:57.100 --> 00:06:00.420
to do and it's not all related to HTTP

00:06:00.420 --> 00:06:03.160
requests being sent back and forth.

00:06:03.880 --> 00:06:06.320
And in such a situation, HTMX also

00:06:06.320 --> 00:06:08.680
might not be perfect, though you could

00:06:08.680 --> 00:06:11.480
also definitely use it for applications like

00:06:11.480 --> 00:06:11.800
this.

00:06:11.960 --> 00:06:14.580
Also, because as I mentioned before,

00:06:15.220 --> 00:06:18.740
you're not limited to just using HTMX.

00:06:18.800 --> 00:06:21.440
You can use it and combine it with

00:06:21.440 --> 00:06:24.240
vanilla JavaScript code or with some

00:06:24.240 --> 00:06:25.880
other JavaScript library.

00:06:26.040 --> 00:06:27.080
You can do that.

00:06:27.420 --> 00:06:29.620
It's not an either-or decision.

00:06:30.440 --> 00:06:34.480
But still, I'd say HTMX shines the most if

00:06:34.480 --> 00:06:37.120
you are building a full-stack web

00:06:37.120 --> 00:06:39.140
application where you do own the

00:06:39.140 --> 00:06:41.900
back-end, where you don't necessarily

00:06:41.900 --> 00:06:45.740
have other clients like a mobile app, and

00:06:45.740 --> 00:06:49.200
where you definitely have not

00:06:49.200 --> 00:06:52.400
necessarily a trivial website, but also not

00:06:52.400 --> 00:06:56.640
a website that is hyper-interactive and

00:06:56.640 --> 00:06:58.800
that got a lot of things going on.

00:06:59.060 --> 00:07:01.340
And it turns out, at least in my

00:07:01.340 --> 00:07:04.900
experience, that quite a few websites are

00:07:04.900 --> 00:07:05.560
like that.

00:07:05.720 --> 00:07:08.120
They are not super complex.

00:07:08.340 --> 00:07:10.960
They don't need a super-interactive,

00:07:11.520 --> 00:07:13.660
complex web user interface.

00:07:13.740 --> 00:07:15.900
Instead, if you're building something like

00:07:15.900 --> 00:07:17.940
an online shop where you're essentially

00:07:17.940 --> 00:07:19.960
fetching products, fetching product

00:07:19.960 --> 00:07:23.440
details, updating a cart, and so on, that's

00:07:23.440 --> 00:07:26.600
something HTMX can do really well.

00:07:27.200 --> 00:07:31.040
You don't necessarily have a UI that

00:07:31.040 --> 00:07:34.340
needs to be powered 100% by JavaScript

00:07:34.340 --> 00:07:37.520
or by JavaScript code you write, to be

00:07:37.520 --> 00:07:38.000
precise.

00:07:38.420 --> 00:07:41.640
Instead, HTMX might be a great choice

00:07:41.640 --> 00:07:43.800
in situations like that.

00:07:44.200 --> 00:07:46.960
And therefore, even if you don't plan on

00:07:46.960 --> 00:07:49.360
taking my course, which is fine, though I,

00:07:49.480 --> 00:07:51.320
of course, am happy if I can welcome

00:07:51.320 --> 00:07:53.900
you there, but even if you don't do that, I

00:07:53.900 --> 00:07:56.240
would definitely recommend that you

00:07:56.240 --> 00:08:00.080
give HTMX a try because it really is an

00:08:00.080 --> 00:08:02.620
amazing library, in my opinion, because

00:08:02.620 --> 00:08:06.120
it can help you write less code, simpler

00:08:06.120 --> 00:08:10.020
code, and build websites quicker than

00:08:10.020 --> 00:08:12.740
you might be able to do with React or

00:08:12.740 --> 00:08:13.100
Next.

00:08:13.380 --> 00:08:18.000
Because I think as web developers, or as

00:08:18.000 --> 00:08:20.900
humans in general, I don't know, we

00:08:20.900 --> 00:08:25.300
sometimes tend to use the wrong tool or

00:08:25.300 --> 00:08:28.360
maybe not the perfect tool for a given

00:08:28.360 --> 00:08:29.040
job.

00:08:29.240 --> 00:08:32.940
And I feel like HTMX can sometimes be

00:08:32.940 --> 00:08:35.240
the better tool for certain kinds of

00:08:35.240 --> 00:08:38.400
websites than React or Angular might

00:08:38.400 --> 00:08:38.640
be.

00:08:38.799 --> 00:08:40.559
Of course, it also comes down to

00:08:40.559 --> 00:08:44.000
personal preference, and that's why I say

00:08:44.000 --> 00:08:45.660
that you should give it a try.

00:08:45.860 --> 00:08:48.040
You don't have to use it, but at least you

00:08:48.040 --> 00:08:50.980
should be able to use it if you want to,

00:08:51.020 --> 00:08:52.440
and you should know about it.

00:08:52.700 --> 00:08:55.620
And therefore, definitely have a look at it

00:08:55.620 --> 00:08:56.920
in the internet.

00:08:57.200 --> 00:08:59.880
As always, you will find lots of opinions

00:08:59.880 --> 00:09:02.800
on it, some pretty extreme opinions in

00:09:02.800 --> 00:09:05.560
both directions, and well, just ignore

00:09:05.560 --> 00:09:05.760
them.

00:09:05.880 --> 00:09:07.500
That's always the best thing to do in the

00:09:07.500 --> 00:09:07.840
internet.

00:09:08.400 --> 00:09:10.580
Don't read what people are writing

00:09:10.580 --> 00:09:12.440
about all these libraries and frameworks.

00:09:12.880 --> 00:09:16.220
Try to find the middle ground and just

00:09:16.220 --> 00:09:17.260
give it a try.

00:09:17.400 --> 00:09:20.260
It's really easy to get started with it, and

00:09:20.260 --> 00:09:22.660
with my course, I, of course, try my best

00:09:22.660 --> 00:09:25.720
to make it as easy as possible, whilst also

00:09:25.720 --> 00:09:28.620
diving a bit deeper into HTMX and

00:09:28.620 --> 00:09:31.880
explaining a bit more about it and also

00:09:31.880 --> 00:09:33.600
showing you more advanced features.

00:09:33.800 --> 00:09:36.700
But you will see, using it is really simple

00:09:36.700 --> 00:09:37.260
in the end.

00:09:37.520 --> 00:09:39.600
In the course, we start at zero, and we

00:09:39.600 --> 00:09:42.040
then gradually dive deeper, but you can,

00:09:42.140 --> 00:09:43.960
of course, also take a look at the official

00:09:43.960 --> 00:09:47.020
docs, also in addition to the course, and

00:09:47.020 --> 00:09:50.800
who knows, maybe HTMX is also a great

00:09:50.800 --> 00:09:53.060
choice for your next project.

00:09:53.660 --> 00:09:57.340
I'm super interested in learning what

00:09:57.340 --> 00:10:00.180
you think about it, so please share your

00:10:00.180 --> 00:10:01.660
opinion on HTMX.

00:10:02.240 --> 00:10:04.080
Let me know if you used it, if you like it,

00:10:04.100 --> 00:10:06.320
what you don't like about it, maybe, and

00:10:06.320 --> 00:10:09.120
well, maybe I also see you in the course.

00:10:09.300 --> 00:10:12.320
But even if I don't, HTMX, in my opinion,

00:10:12.440 --> 00:10:14.720
is pretty amazing, and you also might

00:10:14.720 --> 00:10:15.600
want to give it a try.