HTMX vs AlpineJS - Which should you use for your web app?

HAMY LABS - Podcast
28 Jan 202416:48

Summary

TLDRIn this video, the presenter explores the differences between HTM X and Alpine JS, two low-JS tools for web development. They clarify that these tools are complementary, not competitors, and can be used together for optimal results. HTM X is recommended for server interactivity and partial page reloads, while Alpine JS is better for client-side interactions and when working with JavaScript libraries. The video aims to help developers choose the right tool for their web app's needs and emphasizes the simplicity and efficiency of using low-JS technologies.

Takeaways

  • 🌐 HTM X and Alpine JS are low JS tools that complement each other and can be used together for building modern web apps without the bloat of traditional SPA frameworks.
  • 🔧 HTM X is particularly suited for server interactivity, allowing for partial page reloads and updates based on server data, making it ideal for applications that display and manipulate server-side information.
  • đŸ› ïž Alpine JS is best for client-side interactivity, handling tasks like modals and dropdowns that do not require server interaction and can be managed entirely in the browser.
  • 🚀 Both HTM X and Alpine JS follow the low JS approach, which emphasizes minimal unnecessary baggage, no build steps, and the ability to include them directly from a CDN.
  • 📝 HTM X uses HTML attributes to control element behavior, enabling developers to specify actions in response to user events directly in the markup.
  • 🎯 HTM X is most effective when you have control over server responses and when your app's functionality is tied to data that resides on the server.
  • đŸ›Žïž Alpine JS excels at enhancing user experience with client-side features that do not need to communicate with the server, such as UI elements that are purely interactive.
  • 💡 The combination of HTM X and Alpine JS can cover a broad range of web app development needs, from server-driven data presentation to client-side user interactions.
  • 🌟 The use of HTM X and Alpine JS can lead to faster and cheaper web app development compared to traditional SPA frameworks, and they are not locked into specific technologies like Node.js.
  • 🔗 The flexibility of HTM X and Alpine JS allows for building full-stack applications with the back-end language of your choice, promoting a more diverse and technology-agnostic approach to web development.

Q & A

  • What are HTM X and Alpine JS?

    -HTM X and Alpine JS are low JavaScript (low JS) tools that enable the building of modern web apps without the bloat of popular SPA frameworks like React, Next.js, Svelte, and Vue.js.

  • How are HTM X and Alpine JS different from traditional SPA frameworks?

    -HTM X and Alpine JS are part of the low JS trend, which focuses on providing functionalities with minimal unnecessary baggage. They don't require build steps, can be included directly from a CDN, and use mostly inline attributes for logic.

  • Why are HTM X and Alpine JS considered complementary tools?

    -HTM X and Alpine JS are complementary because they focus on solving common but slightly different aspects of web app development. HTM X is good for server interactivity, while Alpine JS is for client interactivity, and they can often be used together effectively.

  • What is the main advantage of using HTM X for web app development?

    -HTM X excels at server interactivity, allowing for partial page reloads based on data that lives on the server. It simplifies the process of making web pages dynamic and can lead to faster and cheaper web app development.

  • In what scenarios would HTM X be the best choice for building web apps?

    -HTM X is best when you have control over the server and its responses, when your app runs on data only the server knows about, and when your app doesn't need complex or high-speed rendering.

  • What is the unique trait of HTM X?

    -The unique trait of HTM X is its hyperfocus on hypermedia controls, which means it controls everything via HTML attributes, allowing for the definition of how HTML elements should behave in response to user actions or events.

  • How does Alpine JS differ from HTM X in terms of functionality?

    -Alpine JS is designed for client-side interactivity. It's used for functionality that doesn't rely on or impact data that the server has, such as showing or hiding modals, dropdowns, or interacting with JavaScript libraries on the client.

  • What are some examples of client-side functionality where Alpine JS would be the better choice?

    -Alpine JS is suitable for showing or hiding modals, dropdowns, or any interaction that involves JavaScript libraries on the client side, where server involvement is unnecessary and would only slow down the interaction.

  • Why might someone choose to use both HTM X and Alpine JS together in a web app?

    -Using both HTM X and Alpine JS together can provide a powerful combination for web app development. HTM X handles server interactivity and partial page reloads, while Alpine JS takes care of client-side interactions, resulting in a more efficient and user-friendly web app.

  • What benefits does the low JS approach offer over traditional SPA frameworks?

    -The low JS approach offers simplicity, minimal overhead, and the ability to use tools like HTM X and Alpine JS without being locked into a specific technology stack. It allows for faster and cheaper web app development and can be used with any back-end technology.

  • How does the low JS approach relate to the concept of 'full stack' development?

    -The low JS approach supports 'full stack' development by allowing developers to use their preferred back-end language and technologies alongside front-end interactivity tools like HTM X and Alpine JS, without being constrained by the ecosystem of a specific SPA framework.

Outlines

00:00

🌐 Introduction to HTM X vs. Alpine JS

This paragraph introduces the topic of the video, which is a comparison between HTM X and Alpine JS for building web applications. It discusses the advantages of low JS tools like HTM X and Alpine JS over traditional SPA frameworks, emphasizing their simplicity and efficiency. The speaker shares their personal journey with low JS technologies and the decision to use HTM X and F instead of SvelteKit. The paragraph sets the stage for a detailed exploration of when and how to use HTM X and Alpine JS by clarifying that they are complementary tools, not competitors.

05:01

🛠 HTM X for Server Interactivity

The second paragraph delves into the unique capabilities of HTM X, particularly its focus on server interactivity. It explains how HTM X simplifies interactions with server data by allowing partial page reloads, which is a core feature of modern SPAs. The speaker highlights HTM X's hypermedia controls, which enable developers to define how HTML elements should behave in response to user actions directly through HTML attributes. The paragraph also discusses the scenarios where HTM X is most effective, such as when the developer has control over server responses and when the app's functionality relies on server data.

10:02

🔍 Alpine JS for Client Interactivity

Paragraph three shifts the focus to Alpine JS, which is best suited for client-side interactivity. It contrasts HTM X's server-centric approach with Alpine's client-centric one, explaining that Alpine is ideal for user interface elements that do not require server interaction, such as modals and dropdowns. The speaker advocates for the use of Alpine JS when working with third-party JavaScript libraries or when the functionality is entirely client-side. Alpine JS is praised for its ability to add client-side interactivity with minimal overhead, complementing HTM X's server-side capabilities.

15:03

🚀 Conclusion: Embracing the H Stack for Web App Development

The final paragraph concludes the video by summarizing the benefits of using HTM X and Alpine JS together, referring to this combination as the 'H Stack.' It emphasizes the flexibility and efficiency of this approach, which allows developers to build web apps faster and without being locked into a specific technology stack. The speaker shares their positive experience with the H Stack, comparing it favorably to traditional SPA frameworks. The paragraph also hints at other areas of exploration for efficient web app development in 2024, suggesting a broader shift towards simpler, more streamlined development practices.

Mindmap

Keywords

💡Low JS Tools

Low JS Tools refer to lightweight JavaScript frameworks and libraries that are designed to reduce the bloat associated with traditional single-page application (SPA) frameworks. In the context of the video, these tools, such as HTMX and Alpine.js, allow developers to build modern web applications without the overhead of large frameworks like React, Angular, or Vue. The video emphasizes how these tools enable simpler, more efficient web development by focusing on minimalism and direct HTML manipulation.

💡HTMX

HTMX is a high-performance, low-bandwidth, client-side framework that enables developers to create dynamic web applications by enhancing HTML with additional attributes. As mentioned in the video, HTMX is particularly suited for server interactivity, allowing for partial page reloads and updates based on server data. It is highlighted as a powerful tool for building interactive islands within web pages, where specific sections of the page can be dynamically updated without requiring a full page reload.

💡Alpine.js

Alpine.js is a lightweight JavaScript framework that provides data-binding and interactivity capabilities directly within HTML markup. The video discusses how Alpine.js complements HTMX by handling client-side interactivity, such as showing or hiding modals and dropdowns, without the need for server interaction. It is praised for its simplicity and the ease with which it can be integrated into web pages to enhance user experience.

💡Interactive Islands

Interactive Islands is a concept introduced in the video to describe sections of a web page that are dynamic and interactive, often updated based on server data. HTMX is noted for its effectiveness in creating these islands, as it allows for targeted partial page reloads that keep the user interface responsive and fast. This approach contrasts with traditional SPA frameworks that may require more complex state management and full-page updates.

💡Server Interactivity

Server Interactivity, as discussed in the video, refers to the ability of a web application to dynamically interact with and fetch data from the server. HTMX is highlighted for its strengths in this area, as it facilitates partial page updates based on server responses. This is crucial for web applications that display and update data that resides on the server, providing a more dynamic and responsive user experience.

💡Client Interactivity

Client Interactivity pertains to the actions and reactions that occur within the client's browser, independent of server-side data. Alpine.js is recommended for such scenarios, as it allows developers to add client-side functionalities like modals and dropdowns without the need for server communication. This approach is efficient for enhancing user experience on the client side without unnecessary network requests.

💡Complementary Tools

The video emphasizes that HTMX and Alpine.js are complementary tools, not competitors. This means they can be used together in a web development project to leverage their respective strengths. HTMX handles server interactivity, while Alpine.js manages client-side interactions, allowing developers to choose the right tool for the task at hand and create a more efficient development workflow.

💡Minimalist Approach

A minimalist approach in web development, as discussed in the video, involves using the least amount of code and functionality necessary to achieve the desired outcome. Both HTMX and Alpine.js exemplify this philosophy by providing powerful features with minimal JavaScript code, allowing developers to write clean, maintainable, and efficient web applications.

💡Full Stack Development

Full Stack Development refers to the ability to develop both the front-end and back-end of a web application. The video mentions how using HTMX and Alpine.js allows for full stack development without being locked into a specific technology stack. This flexibility enables developers to choose their preferred back-end language or framework while still benefiting from efficient front-end interactivity.

💡Hypermedia Controls

Hypermedia Controls are HTML attributes that dictate how HTML elements should behave in response to user actions or events. HTMX is unique in its hyperfocus on these controls, allowing developers to define behaviors directly in the HTML markup. This capability is central to HTMX's ability to perform partial page updates and server interactions, as it enables the creation of dynamic web applications with minimal additional code.

Highlights

HTM X and Alpine JS are low JS tools that allow building modern web apps without the bloat of popular SPA frameworks.

HTM X and Alpine JS are complementary and can be used together, focusing on different aspects of web app development.

Low JS tools provide functionalities with minimal unnecessary baggage, often including no build steps and minimal JS.

HTM X is particularly good for server interactivity and partial page reloads based on data from the server.

Alpine JS is suitable for client-side interactivity that doesn't require server interaction, such as modals and dropdowns.

HTM X works well when you have control over the server and its responses, as it expects HTML to be returned.

Alpine JS is ideal for functionality that is client-side only and does not need to update or display server data.

HTM X is not suitable for apps that require complex or high-speed rendering, as network calls to the server may not be fast enough.

Alpine JS can be used alongside HTM X to fill in gaps for client-side interactivity that doesn't require server involvement.

Using HTM X and Alpine JS allows for building web apps faster and cheaper than traditional SPA frameworks.

The 'H stack' approach with HTM X and any back-end language provides flexibility without locking into a specific tech stack.

The video discusses the author's personal journey and preference for HTM X and Alpine JS over other SPA frameworks.

HTM X and Alpine JS enable a simpler and more straightforward development cycle compared to complex SPA frameworks.

The video provides an overview of how to build full-stack HTM X apps with a back-end of choice.

The author shares their reasons for moving from Next.js to a stack that includes HTM X and Alpine JS for front-end interactivity.

The video concludes with a recommendation for the 'H stack' approach for building web apps that require server interactivity.

Transcripts

play00:00

hey everyone welcome back to the lab in

play00:02

this video we're going to be comparing

play00:03

HTM X versus Alpine JS and specifically

play00:07

answering the question which one should

play00:09

you use for building your web app so low

play00:12

JS tools like htx and Alpine are the

play00:15

future of the web they allow us to build

play00:18

modern web apps without the bloat of

play00:20

popular Spa Frameworks these are things

play00:22

like react nextjs spel kit vgs you know

play00:26

they're better than what came before but

play00:27

they are not uh as great as is they

play00:30

could be now I've been researching and

play00:31

experimenting with low JS Technologies

play00:33

for the past year eventually deciding to

play00:35

build my apps with htx and F instead of

play00:38

spoke kit I found that the ljs approach

play00:41

is much simpler while providing all the

play00:44

power I need to build modern web app now

play00:46

one of the things that took me a while

play00:47

to understand and that I see a good

play00:50

amount of confusion about in the

play00:51

community is how to choose between ljs

play00:53

tools HTM X and Alpine for building your

play00:56

own web apps some guides will use one

play00:59

some will use the other and then many

play01:01

will use both and so in this post I want

play01:04

to clarify the differences so you can

play01:05

make the best choice for your web app

play01:07

and start building and stop bike

play01:09

shedding the first thing I want to note

play01:11

is that HTM X and Alpine JS are

play01:13

complimentary so the decision between

play01:15

htx and Alpine JS is not an exclusive

play01:18

one these are not competing tools

play01:21

offering the same functionality though

play01:22

there is overlap in what each of them

play01:24

can do so this isn't like a choice

play01:26

between react or view or angular or

play01:28

spelt in which case they're kind of

play01:30

doing overlapping things in different

play01:32

ways and so you're probably going to

play01:34

choose one to do most of your work um

play01:37

here there is some overlap but often you

play01:40

can use them together and often that's

play01:42

what you will want to do and so they're

play01:44

complimentary and they work well

play01:45

together because they focus on solving

play01:47

common but slightly different aspects of

play01:50

web app development and so this is why

play01:52

using both of them is sometimes more

play01:54

powerful than using just one and another

play01:57

aspect that they have that is kind of

play01:58

fundamental to this new trend um or

play02:01

pattern of libraries we're seeing that

play02:03

that we're calling ljs is that they're

play02:05

going to provide these functionalities

play02:07

with like minimal unnecessary baggage

play02:09

and so some examples of this that you

play02:12

know we might have come to expect or to

play02:15

be the norm with a lot of these like

play02:17

bloated client side uh single page

play02:19

application Frameworks um logs kind of

play02:22

takes a different approach and so

play02:23

there's no build steps you can just

play02:25

include it from a CDN on your web page

play02:27

and you can just use it so you don't

play02:29

have to worry about npm you don't have

play02:31

to worry about setting up Vite or Turbo

play02:33

or bun or whatever random new build tool

play02:36

JS comes out with just include it on the

play02:38

page just use it it works um there's

play02:41

very minimal JS so we're using mostly

play02:43

inline attributes and so what this

play02:45

allows us to do is we can basically

play02:47

build all the logic and stuff directly

play02:49

in our markup and just send it so this

play02:51

could be a static page it could be a

play02:54

server side rendered page um and it will

play02:56

just have the functionality in the mark

play02:59

up and so we don't have to write all

play03:01

these like crazy framework things that

play03:03

these Spas are doing we don't have to

play03:04

worry about all this other overhead um

play03:06

it's very simple to see when you look at

play03:08

the markup this is what the thing is

play03:10

doing um there's not like some file from

play03:12

100 files away that's being pulled in

play03:14

randomly and and causing weird Behavior

play03:16

and the next one is that they're very

play03:17

easy to compose because there's no build

play03:19

steps because there's minimal JS because

play03:21

the logic is in the markup it's very

play03:24

easy to see how these aren't going to

play03:26

affect each other you can sprinkle them

play03:27

in in the web page where you want they

play03:29

only

play03:30

affect kind of that local markup um and

play03:33

so you can use a little bit of it and

play03:35

you don't have to infect your entire um

play03:38

code base with that choice um which

play03:41

unfortunately you do mostly have to do

play03:43

with the single page application

play03:44

Frameworks um because they all rely on

play03:46

node and they all have a specific way of

play03:48

doing things and if you don't play with

play03:50

the life cycle uh it just doesn't work

play03:52

as well um but you can do that with

play03:54

these low. JS tools and so these work

play03:56

well together which is why you'll see

play03:57

just as many apps using both HTML X and

play04:00

Alpine as you will just Alpine or just

play04:02

HTM X and often what you'll see is a few

play04:05

of these low JS tools will be used um

play04:07

together so it might be htx and Alpine

play04:09

but you could swap in a different one

play04:11

for either of those that are kind of

play04:13

focused on specific aspect of web app

play04:16

development okay so now that we've seen

play04:18

the similarities of these libraries

play04:19

let's talk about how each is uniquely

play04:21

solving things what each is uniquely

play04:23

good at in the web app development

play04:24

sphere so you're going to want to use HT

play04:26

Max for server interactivity and

play04:29

basically think about using htx we often

play04:31

are thinking about using interactive

play04:32

Islands um and so basically most web

play04:35

pages are mostly static and then we've

play04:36

got some widgets on the page that are

play04:38

like doing stuff this is where htx

play04:40

shines and where it really shines is

play04:41

because it allows you to do partial page

play04:43

reloads um and so when you do this you

play04:45

can easily make your page Dynamic Based

play04:48

on data that lives on the server and

play04:50

most web apps really just display data

play04:52

that's on the server and hmx is really

play04:55

good at this so for Server interactivity

play04:56

when you want to access data on the

play04:58

server that is what h hmx excels at um

play05:01

and this is my overview of interactive

play05:02

Islands uh this is from my guide using F

play05:06

and HTM X for simple Interac vience and

play05:08

you can check that out there okay so hmx

play05:10

is focused on making server

play05:11

interactivity simple and Powerful its

play05:14

unique trait is that it's hyperfocused

play05:16

on hyper media controls what this means

play05:18

for us is that it controls everything

play05:20

via HTML attributes HTML being a hyper

play05:23

media you can tell HTML elements how

play05:26

they should behave when a user does

play05:28

something or an EV e curse so you can

play05:30

say like if you click this button send

play05:33

out this um request to the server or

play05:35

after 30 seconds send out this request

play05:38

to the server and so it'll send a

play05:40

request to the server based on um you

play05:43

know you have a trigger here it'll send

play05:44

a request to the server you'll have an

play05:46

attribute saying what do you want me to

play05:47

send to the server where does it go um

play05:50

and then you can then say this is what

play05:53

you do with the HTML that is returned

play05:55

and what this allows us to do is swap

play05:57

out partial pages and this is this is

play06:00

really important it's this partial page

play06:02

reload that gives this superpowers now

play06:04

this may not seem like much but the

play06:06

ability to do partial page reloads and

play06:08

in particular targeted partial page

play06:10

reloads is actually the fundamental

play06:13

thing that Spa the single page

play06:15

applications are doing to feel fast when

play06:17

we think about it what is spell and spel

play06:20

kit doing what is react and nextjs doing

play06:22

what is vuejs and N doing what they're

play06:25

doing the fundamental thing they're

play06:26

doing is that they have a backing data

play06:28

store and they connect it to the UI

play06:30

that's rendered and then when the data

play06:32

store changes they are only partially

play06:35

reloading the UI that that is the

play06:37

fundamental value proposition that they

play06:39

bring is that they're doing partial page

play06:41

reloads and this makes it feel fast and

play06:43

it makes it feel Dynamic and so htx

play06:46

allows you to build these same modern

play06:48

feeling apps because it gives you the

play06:50

power to do these partial page reloads

play06:52

directly in your markup but because it's

play06:54

in the markup without the extra baggage

play06:56

this is simpler faster and cheaper to

play06:58

build okay okay so that's how it does

play07:00

that so when should you use HT Max and I

play07:04

think there's a few cases here and these

play07:06

are basically um ands so so if any of

play07:09

these fails htx might not be the best

play07:11

tool at least for that one particular

play07:14

type again it's highly composable so you

play07:16

can use it in Parts where you need it

play07:17

and then if you have a special case you

play07:19

can go use something else that's better

play07:20

suited the first one is when you have

play07:22

control over the server and its

play07:23

responses so hmx does expect HTML

play07:26

returns which is different from a lot of

play07:27

libraries a lot of apis and stuff going

play07:29

to try to return you Json or whatever

play07:31

their you know RPC binary format is but

play07:34

it does expect HTML to be returned so

play07:36

what you're going to need to be able to

play07:37

do is modify the server endpoints

play07:39

because if you want to change the the

play07:40

HTML that's being returned you want to

play07:42

change the UI the controls um how it

play07:44

interacts with the server you need to be

play07:46

able to change that HTML you need

play07:48

control over the server if you don't

play07:50

have control over the server for

play07:51

whatever reason um then htx is probably

play07:53

not going to work that well for you uh

play07:55

because you're going to lose that

play07:56

control the next time when you should

play07:58

use HTM Max is um when your app runs on

play08:00

data only the server knows about now any

play08:03

app that persists data or does crud

play08:05

operations does this right like if you

play08:07

think about what most apps are doing

play08:09

they're really just reading data from

play08:12

the back end and and getting the data on

play08:14

the front end they're trying to display

play08:15

the data they're trying to allow users

play08:17

to do stuff on the data so this is most

play08:19

apps actually even though this seems

play08:21

really you know simple so most apps do

play08:24

this but if your thing is only doing

play08:26

things that exist in the browser um

play08:29

these are things like JavaScript based

play08:31

calculators or maybe you have like an

play08:33

image editor that like is doing

play08:34

everything locally maybe even like a

play08:36

video game that's that's all running

play08:38

locally and there's no like back syncing

play08:41

there's no UI syncing from the server um

play08:43

basically everything's rendered front in

play08:45

then HDMX probably won't help that much

play08:48

um so for most apps like you know

play08:49

they're just doing the server stuff HDMX

play08:51

great but if it's just client side stuff

play08:53

like you know HDMX doesn't really need

play08:55

going to help you much because the

play08:57

server doesn't need to get involved in

play08:58

that stuff stuff okay and then the next

play09:00

time when htx is good is when your app

play09:02

doesn't need complex or high-speed

play09:04

rendering um and so HDMX is quite fast

play09:07

and in many cases it's much faster than

play09:09

Spas when data needs to be read and

play09:11

returned from the server because it

play09:13

skips a whole layer of logic for um API

play09:16

needing to serialize to a specific form

play09:18

and then you got to send it over the

play09:20

wire and then the client needs to

play09:22

deserialize this thing and then it needs

play09:24

to parse that data out to understand it

play09:26

and then it's got to turn that data into

play09:28

something usable based on its own

play09:30

business logic to turn it into um the

play09:32

actual UI we kind of skip that whole

play09:34

step because a server just does it and

play09:35

just sends you a thing and it's like use

play09:37

this so often for these like things

play09:40

where we need server data hmax is

play09:42

actually quite fast and faster um than

play09:44

these other Frameworks but that doesn't

play09:45

mean that you know it's still a network

play09:47

request this isn't for free um and so if

play09:49

you're building something that needs to

play09:51

run at like 60 FPS that's doing a lot of

play09:54

like frame rerenders um like a video

play09:56

game or something like that then like a

play09:58

network call to the server just just

play09:59

will never be fast enough to kind of do

play10:01

the updates um and so you should really

play10:03

reach for like a more specialized local

play10:05

rendering engine you know whether it's

play10:06

like phaser or um I don't know use like

play10:10

wasm or something so that's actually

play10:11

fast locally that's what you're going to

play10:13

need to kind of support that very fast

play10:15

back and forth but most apps don't need

play10:17

this like unless you're building a video

play10:19

game really you you won't need that but

play10:21

in that case you you wouldn't want htx

play10:23

probably and so to conclude you know htx

play10:25

is great for building web apps that

play10:27

require server interactivity and where

play10:29

you're displaying and updating data

play10:31

located on the server which again most

play10:33

web apps and even for web apps that

play10:35

don't do this a majority of the codebase

play10:37

is going to be doing this so still very

play10:39

good for adding this kind of

play10:41

interactivity sprinkling it in to your

play10:43

code base and so for these cases reach

play10:45

for HDMX great tool for this okay so

play10:47

that's htx and for Alpine we want to use

play10:50

Alpine for client interactivity and so

play10:52

while most interactivity you know

play10:54

probably 80 plus% of what you might want

play10:56

to do in a web app um this works well

play10:59

with HTM X's SSR HTML approach because

play11:02

again most web apps basically just

play11:05

displaying and updating data on the

play11:07

server um it may not be the best tool

play11:10

for everything so for example there are

play11:12

some things we might want to build to

play11:14

make the user experience better that

play11:16

doesn't rely on or impact in any way the

play11:19

data that the server has and so these

play11:21

are going to be things like you know

play11:23

showing or hiding a modal um so like if

play11:25

I were to like click this and it pops up

play11:27

a modal or and then I click something

play11:29

else and the modal disappears like the

play11:31

server doesn't need to be involved in

play11:33

that because like I'm not changing data

play11:36

I'm not uh I don't need to read Dynamic

play11:38

data it's just stuff that's on the web

play11:40

page already and it's like oh I should

play11:41

show the user I should get it out it's

play11:43

just it's augmenting the U but the

play11:45

server just doesn't need to be involved

play11:46

in that it's not adding anything another

play11:48

example of this is like if we're

play11:49

interacting with a JavaScript library on

play11:51

a web page like I don't know if we're

play11:52

doing math or something maybe we have

play11:53

like a math calculator like JavaScript

play11:56

library and we want to say like here's

play11:58

the inputs from the user user give me

play11:59

the the thing back like the server

play12:01

wouldn't add anything in this

play12:02

interaction because we have everything

play12:05

locally um or maybe it's a map Library

play12:07

like the map only exists in our client

play12:10

so we don't need to ask the server about

play12:12

this we just need to tell the JavaScript

play12:14

map library to like change or whatever

play12:17

for these things that only live on the

play12:18

client and they don't gain anything from

play12:21

asking the server for information or

play12:23

they don't need to update the data that

play12:25

exists on the server then it doesn't

play12:27

really make sense to do that server

play12:29

Network call and in fact trying to ask

play12:31

the server for this information or

play12:33

trying to get the server involved in

play12:34

this thing that's really only client

play12:35

only can often be awkward because it's

play12:39

like why are we doing this like it's

play12:40

unnecessary um and slow it's just like a

play12:42

network called will never be as fast as

play12:44

like a local thing so if you don't need

play12:46

to make a network call if there's no

play12:47

need for that then like don't and so

play12:49

this is where Alpine really shines and

play12:51

why Alpine or really any other um kind

play12:54

of lightweight client interactivity

play12:56

library is often used alongside h htx

play12:59

htx is really great for the server

play13:01

interactivity but for client side stuff

play13:03

when we don't need the server

play13:04

interactivity you'll often use something

play13:05

else could be like Alpine jQuery

play13:08

hyperscript things like that so kind of

play13:10

get you the the extra 20% of the way to

play13:12

improve your ux now Alpine JS takes a

play13:15

similar ljs approach allowing you to

play13:17

declare client side state and

play13:19

functionality in a simple concise way

play13:21

directly in your HTML and this allows it

play13:23

to play very nice with HT Max as all

play13:25

your minimal logic declarations can be

play13:27

declared and viewed all in one place

play13:29

which kind of serves the locality of

play13:30

behavior principle um and so HTM X

play13:32

you're just doing HTML attributes it's

play13:35

really just right in the markup and same

play13:36

with alpine for the most part um it's

play13:39

all going to be directly in your markup

play13:41

and then you have the option of adding a

play13:43

little bit of extra JavaScript that

play13:45

plugs into your Alpine if you want to do

play13:47

something a little bit more fancy okay

play13:48

so when should you use Alpine JS um the

play13:51

first one is when you have functionality

play13:53

that is client side only as we kind of

play13:55

talked about you know the most common

play13:56

examples of this is like showing or

play13:58

hiding a modal or maybe a drop down like

play14:00

a hamburger menu stuff like that this

play14:02

stuff really only exists on the client

play14:03

to augment the user experience and the

play14:05

server doesn't need to know about this

play14:06

and it doesn't really make sense to wait

play14:08

on a network call for it so things like

play14:10

this where the server just it doesn't

play14:12

care if it's open or closed it only

play14:14

cares what like the end action is like

play14:16

just you know don't ask the server for

play14:18

it just do it on the client the next one

play14:20

is when you need to interact with JS

play14:21

libraries on the client so you know

play14:22

JavaScript has a massive ecosystem it's

play14:24

likely you're going to want to leverage

play14:25

some third party libraries for

play14:27

visualizations or drag and drops or you

play14:29

know anything like that and for these

play14:30

like you might as well just use

play14:31

JavaScript for easier integration um

play14:34

you're going to have to do that anyway

play14:35

you don't need to get into the like wait

play14:37

on a network call to send you back

play14:39

something and then you run it like

play14:40

Alpine gives you these simple life cycle

play14:42

hooks you can run it directly on the

play14:43

client you can use browser native events

play14:46

so you know don't make things hard on

play14:47

yourself just like use use the little

play14:49

JavaScript here and so Alpine JS is

play14:51

really great for sprinkling client

play14:52

interactivity in your app with minimal

play14:54

JavaScript overhead so when it doesn't

play14:56

make sense to ask the server something

play14:58

Alpine JS can fill in the gaps next so

play15:01

far I've really been enjoying building

play15:03

web apps with HDMX and Alpine I found it

play15:05

allows me to build my web apps faster

play15:06

and cheaper than the Spas ever did plus

play15:09

it doesn't lock me into a specific

play15:10

technology like node uh so I can build

play15:12

full stack apps with f my favorite

play15:14

language and hmx and Alpine for

play15:16

front-end interactivity and this is the

play15:18

power of the H stack hyper media on

play15:20

whatever you like and really what these

play15:22

low JS Technologies unlock is that you

play15:24

don't get bound into this whole

play15:27

ecosystem to just like use this one

play15:29

thing which unfortunately like you know

play15:31

react and spelt and angular and view say

play15:34

that you're not locked in but you kind

play15:37

of have to run node or something or some

play15:40

build tool in order to get it to work so

play15:42

it's very unwieldy to use in any other

play15:44

kind of back end and that's why we end

play15:46

up with all these new full stack things

play15:47

which are nextjs n spell kit and all

play15:50

those things which are trying to make

play15:51

this easier but again it's like you're

play15:53

just making it more explicit that I am

play15:55

bound into this whole Tech stack when I

play15:57

didn't want to use this anyway all I

play15:58

want wanted was just to make it easy to

play15:59

make frun end so the power of the house

play16:01

stack this is why we like low JS now if

play16:03

you like this post you might also like

play16:05

three areas I'm exploring to build more

play16:07

side projects faster and cheaper in 2024

play16:09

low JS is one of these also exploring

play16:11

some other things really trying to make

play16:13

my development cycle just simpler and

play16:15

nicer and honestly better um than kind

play16:18

of what's been popular for the past 5

play16:19

years because it's it's just too

play16:21

complicated we don't need that um the

play16:22

next one is simple interactive island

play16:23

with FP and htx kind of giving an

play16:25

overview of how I'm thinking about

play16:27

building full stack HTM X apps um on my

play16:29

back end of choice and then you might

play16:31

also be interested in why I'm moving

play16:32

from spel kit to F which kind of goes

play16:34

through my journey of falling in and out

play16:37

of like with these Spa Frameworks um and

play16:40

then kind of how I found something

play16:41

better and then decided that that was

play16:43

like the right path to go that's it for

play16:45

this video thanks for watching and I'll

play16:47

see you in the next one

Rate This
★
★
★
★
★

5.0 / 5 (0 votes)

Étiquettes Connexes
Web DevelopmentHTM XAlpine JSLow JSFramework ComparisonServer InteractivityClient InteractionFull StackFront-endWeb Apps
Besoin d'un résumé en anglais ?