htmx Is Pro-JavaScript

Rate this content
Bookmark
HTMX is a powerful front-end library that extends HTML and integrates seamlessly with JavaScript. It allows developers to use HTML attributes to manage Hypermedia exchanges, reducing the need for extensive JavaScript coding. Key features include attributes like hx-get, hx-post, hx-put, hx-delete, hx-trigger, and hx-target, which handle HTTP requests and responses. HTMX excels in partial page updates, making web applications more dynamic and responsive. It is not an anti-JavaScript library; rather, it complements JavaScript by offloading server synchronization tasks. The sortable demo showcases how HTMX can work with JavaScript libraries like Sortable.js to enhance user interfaces. This makes HTMX a valuable tool for building interactive web applications with minimal JavaScript.

From Author:

In this talk we will take a look at an idiosyncratic javascript library, htmx, which is designed to make HTML more powerful as a hypermedia. It does this by generalizing the idea of hypermedia controls such as anchor tags and forms. Web developers who use htmx typically do not write nearly as much javascript as they would if they chose a more popular SPA javascript library for their front end needs. In this way, htmx can help address "JavaScript Fatigue", a general sense of being overwhelmed by the JavaScript world.


htmx is sometimes held up as a library "for people who hate JavaScript". Ironically, however, by dramatically reducing the amount of JavaScript a web developer must write to build a web application, htmx can make the JavaScript that a developer wants to write much more enjoyable, making writing JavaScript a playful, high-value and fun part of a broader web application rather than a chore that must be dealt with to accomplish simple tasks.

This talk has been presented at JSNation 2024, check out the latest edition of this JavaScript Conference.

FAQ

You can find more examples of HTMX capabilities on the HTMX website at htmx.org/examples.

Carson Gross is the creator of HTMX.

HTMX is a Hypermedia-oriented front-end library written in JavaScript that extends HTML and allows developers to create interactive web applications with minimal JavaScript.

Unlike libraries such as React, which replace HTML and work with a JSON API to update the user interface, HTMX extends HTML and uses attributes to drive Hypermedia exchanges without requiring a lot of JavaScript.

Hypermedia controls in HTMX are elements like links and forms that use attributes to trigger HTTP requests and handle responses, allowing for interactive web applications.

Yes, with HTMX, you often don't need to write a lot of JavaScript. Instead, you use HTML attributes to define behaviors and interactions.

Key attributes in HTMX include hx-get, hx-post, hx-put, hx-delete, hx-trigger, and hx-target, which allow elements to issue HTTP requests and handle responses.

HTMX allows for partial page updates by using the hx-target attribute to specify where the returned HTML content should be inserted, without replacing the entire viewport.

No, HTMX is not anti-JavaScript. It aims to complement JavaScript by handling server synchronization, allowing JavaScript to focus on client-side scripting and user interface enhancements.

With HTMX, you can build interactive web applications that have functionalities similar to single-page applications (SPAs) without relying heavily on JavaScript.

Carson Gross
Carson Gross
22 min
17 Jun, 2024

Comments

Sign in or register to post your comment.

Video Transcription

Available in Español: htmx es Pro-JavaScript

1. Introduction to HTMX and its Benefits

Short description:

Hi, I'm Carson Gross, the creator of HTMX, an alternative front-end library in JavaScript. In this talk, I'll explain what HTMX is and why it can be a pro JavaScript library. I'll provide an overview, discuss the relationship between HTMX and JavaScript, and demonstrate an HTMX demo. HTMX is a Hypermedia-oriented front-end library that extends HTML and works with a JSON API, unlike other libraries that replace HTML. As an HTMX developer, you don't need to write a lot of JavaScript.

Hi, my name is Carson Gross and I'm going to give a talk on HTMX. I'm the creator of HTMX, which is sort of an alternative front-end library written in JavaScript. And the title of this talk is that HTMX is pro JavaScript. And so what I'm going to talk about is what HTMX is and then talk to you about how I feel that it can be a pro JavaScript library, despite what some people say about it.

So just some background on me. I have a consulting company called Big Sky Software, and that's mainly for open source work. I've got some projects like HTMX. It's probably the biggest one. And then a couple of other ones, HyperScript. I've got a somewhat funny page on development called Gregbrain.dev. And then I've got a book out of the HTMX that I show you. And this talk is of interest to you. You might check out Hypermedia Systems. It's available online for free, or you can buy a hard copy or a Kindle version if you'd like.

So what are we going to do in this talk? Well, I'm going to look at HTMX really quick. Give people who don't know about it, or maybe you've just heard about it in passing, an overview of what it is. And look at the relationship between HTMX and JavaScript. And then I'm going to show an HTMX demo. And then what I want to do after that demo is think a little bit about how HTMX and JavaScript interact. And maybe, again, try and change the way that people are talking about HTMX and JavaScript. So HTMX, what is this thing? Well, it's what I call a Hypermedia-oriented front-end library. And what it does is a lot of JavaScript libraries that people are familiar with today, like React and so forth, what they do is they tend to replace HTML. So you don't use links and forms in the traditional way that you would have in the past with HTML. Instead, you have a fairly elaborate front-end code base that's working with a JSON API. And then React or whatever is reactively updating the user interface. And so HTMX is a little different in that it really tries to extend HTML and live in the Hypermedia world that HTML sort of gives us. So with an HTMX-based application, you're typically not writing a ton of JavaScript yourself. HTMX itself is written in JavaScript. I'll emphasize that again a couple of times. But you, as an HTMX developer, often don't need to write a ton of JavaScript.

2. Understanding HTMX and Hypermedia Controls

Short description:

With HTMX, you put attributes in your HTML that drive Hypermedia exchanges. HTMX is a JavaScript library that hooks into these attributes and adds behaviors. It builds on the idea of Hypermedia controls, such as links and forms. Links allow for nonlinear branching, while forms give HTML authors more control over requests. HTMX generalizes these concepts and handles events like clicking on elements.

Instead, what you do with HTMX is you put attributes in your HTML, and those attributes sort of drive what I call Hypermedia exchanges. And so what HTMX does is a JavaScript library that looks those things up and then hooks in behaviors, sort of the standard event handler mechanism for that. So at a conceptual level, what HTMX is building on is this idea of Hypermedia controls. And Hypermedia controls, again, not super JavaScript-oriented, but just let me give you the background on this.

What Hypermedia controls are are things like links and forms. So this is sort of the link in HTML. This is the canonical Hypermedia control. This was sort of the original Hypermedia control. And the thing that makes this a Hypermedia control in particular is this little attribute, this href, which effectively tells the browser, when someone clicks on this link, get this page. And this allows for what's called nonlinear branching.

Now there's one other major Hypermedia control, for user interactivity anyways, in HTML, and that's the form tag. And form tags are a little bit more sophisticated than links. I won't go into the details of it, but except to note that the form tag with this method attribute gives HTML authors more control over the form of the request that's issued. So links issue gets and that's all they can do. Forms can issue gets and posts. And they also have a more complicated relationship with the tags inside of them. So to understand what HTMX is trying to do, let's really zero in on what this anchor tag means. What does this mean? Again, I'm sorry. I apologize if you're just interested in JavaScript, but we're going to talk a little bit about HTML here.

So what does this really mean for a browser? Well, what it tells the browser is, okay, render this bit of text on the page and probably show it in some mechanism with an affordance, with some sort of visual cue indicating that it's clickable. And then, when a user clicks on that, what it's going to do is it's going to issue an HTTP get to this about URL, and it's going to get back an HTML response, typically. And what that HTML response is going to then do is it's going to replace the entire viewport of the browser. So that's what links, from a hypermedia mechanic standpoint, that's what links do. So what HTML, or excuse me, what HTMX does is it generalizes each of these ideas. So there's an event here. I clicked on this thing.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Building Better Websites with Remix
React Summit Remote Edition 2021React Summit Remote Edition 2021
33 min
Building Better Websites with Remix
Top Content
Remix is a web framework built on React Router that focuses on web fundamentals, accessibility, performance, and flexibility. It delivers real HTML and SEO benefits, and allows for automatic updating of meta tags and styles. It provides features like login functionality, session management, and error handling. Remix is a server-rendered framework that can enhance sites with JavaScript but doesn't require it for basic functionality. It aims to create quality HTML-driven documents and is flexible for use with different web technologies and stacks.
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Watch video: Speeding Up Your React App With Less JavaScript
Mishko, the creator of Angular and AngularJS, discusses the challenges of website performance and JavaScript hydration. He explains the differences between client-side and server-side rendering and introduces Quik as a solution for efficient component hydration. Mishko demonstrates examples of state management and intercommunication using Quik. He highlights the performance benefits of using Quik with React and emphasizes the importance of reducing JavaScript size for better performance. Finally, he mentions the use of QUIC in both MPA and SPA applications for improved startup performance.
Full Stack Documentation
JSNation 2022JSNation 2022
28 min
Full Stack Documentation
Top Content
The Talk discusses the shift to full-stack frameworks and the challenges of full-stack documentation. It highlights the power of interactive tutorials and the importance of user testing in software development. The Talk also introduces learn.svelte.dev, a platform for learning full-stack tools, and discusses the roadmap for SvelteKit and its documentation.
SolidJS: Why All the Suspense?
JSNation 2023JSNation 2023
28 min
SolidJS: Why All the Suspense?
Top Content
Suspense is a mechanism for orchestrating asynchronous state changes in JavaScript frameworks. It ensures async consistency in UIs and helps avoid trust erosion and inconsistencies. Suspense boundaries are used to hoist data fetching and create consistency zones based on the user interface. They can handle loading states of multiple resources and control state loading in applications. Suspense can be used for transitions, providing a smoother user experience and allowing prioritization of important content.
From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
Tom Pressenwurter introduces Redwood.js, a full stack app framework for building GraphQL APIs easily and maintainably. He demonstrates a Redwood.js application with a React-based front end and a Node.js API. Redwood.js offers a simplified folder structure and schema for organizing the application. It provides easy data manipulation and CRUD operations through GraphQL functions. Redwood.js allows for easy implementation of new queries and directives, including authentication and limiting access to data. It is a stable and production-ready framework that integrates well with other front-end technologies.
RedwoodJS: The Full-Stack React App Framework of Your Dreams
React Summit Remote Edition 2021React Summit Remote Edition 2021
43 min
RedwoodJS: The Full-Stack React App Framework of Your Dreams
Top Content
Redwood JS is a full stack React app framework that simplifies development and testing. It uses a directory structure to organize code and provides easy data fetching with cells. Redwood eliminates boilerplate and integrates Jest and Storybook. It supports pre-rendering and provides solutions for authentication and deployment. Redwood is a cross-client framework that allows for building web and mobile applications without duplicating work.

Workshops on related topic

Building WebApps That Light Up the Internet with QwikCity
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Miško Hevery
Miško Hevery
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
Back to the Roots With Remix
React Summit 2023React Summit 2023
106 min
Back to the Roots With Remix
Featured Workshop
Alex Korzhikov
Pavlik Kiselev
2 authors
The modern web would be different without rich client-side applications supported by powerful frameworks: React, Angular, Vue, Lit, and many others. These frameworks rely on client-side JavaScript, which is their core. However, there are other approaches to rendering. One of them (quite old, by the way) is server-side rendering entirely without JavaScript. Let's find out if this is a good idea and how Remix can help us with it?
Prerequisites- Good understanding of JavaScript or TypeScript- It would help to have experience with React, Redux, Node.js and writing FrontEnd and BackEnd applications- Preinstall Node.js, npm- We prefer to use VSCode, but also cloud IDEs such as codesandbox (other IDEs are also ok)
Let AI Be Your Docs
JSNation 2024JSNation 2024
69 min
Let AI Be Your Docs
Workshop
Jesse Hall
Jesse Hall
Join our dynamic workshop to craft an AI-powered documentation portal. Learn to integrate OpenAI's ChatGPT with Next.js 14, Tailwind CSS, and cutting-edge tech to deliver instant code solutions and summaries. This hands-on session will equip you with the knowledge to revolutionize how users interact with documentation, turning tedious searches into efficient, intelligent discovery.
Key Takeaways:
- Practical experience in creating an AI-driven documentation site.- Understanding the integration of AI into user experiences.- Hands-on skills with the latest web development technologies.- Strategies for deploying and maintaining intelligent documentation resources.
Table of contents:- Introduction to AI in Documentation- Setting Up the Environment- Building the Documentation Structure- Integrating ChatGPT for Interactive Docs
Learn Fastify One Plugin at a Time
Node Congress 2021Node Congress 2021
128 min
Learn Fastify One Plugin at a Time
Workshop
Matteo Collina
Matteo Collina
Fastify is an HTTP framework for Node.js that focuses on providing a good developer experience without compromising on performance metrics. What makes Fastify special are not its technical details, but its community which is wide open for contributions of any kind. Part of the secret sauce is Fastify plugin architecture that enabled developers to write more than a hundred plugins.This hands-on workshop is structured around a series of exercises that covers from basics "hello world", to how to structure a project, perform database access and authentication.

https://github.com/nearform/the-fastify-workshop
Build a Universal Reactive Data Library with Starbeam
JSNation 2023JSNation 2023
66 min
Build a Universal Reactive Data Library with Starbeam
WorkshopFree
Yehuda Katz
Yehuda Katz
This session will focus on Starbeam's universal building blocks. We'll use Starbeam to build a data library that works in multiple frameworks.We'll write a library that caches and updates data, and supports relationships, sorting and filtering.Rather than fetching data directly, it will work with asynchronously fetched data, including data fetched after initial render. Data fetched and updated through web sockets will also work well.All of these features will be reactive, of course.Imagine you filter your data by its title, and then you update the title of a record to match the filter: any output relying on the filtered data will update to reflect the updated filter.In 90 minutes, you'll build an awesome reactive data library and learn a powerful new tool for building reactive systems. The best part: the library works in any framework, even though you don't think about (or depend on) any framework when you built it.
Table of contents- Storing a Fetched Record in a Cell- Storing multiple records in a reactive Map- Reactive iteration is normal iteration- Reactive filtering is normal filtering- Fetching more records and updating the Map- Reactive sorting is normal sorting (is this getting a bit repetitive?)- Modelling cache invalidation as data- Bonus: reactive relationships
Build a Product Page with Shopify’s Hydrogen Framework
React Advanced Conference 2022React Advanced Conference 2022
81 min
Build a Product Page with Shopify’s Hydrogen Framework
WorkshopFree
David Witt
David Witt
Get hands on with Hydrogen, a React-based framework for building headless storefronts. Hydrogen is built for Shopify commerce with all the features you need for a production-ready storefront. It provides a quick start, build-fast environment so you can focus on the fun stuff - building unique commerce experiences. In this workshop we’ll scaffold a new storefront and rapidly build a product page. We’ll cover how to get started, file-based routing, fetching data from the Storefront API, Hydrogen’s built-in components and how to apply styling with Tailwind.You will know:- Get started with the hello-world template on StackBlitz- File-based routing to create a /products/example route- Dynamic routing /products/:handle- Hit the Storefront API with GraphQL- Move the query into the Hydrogen app- Update the query to fetch a product by handle- Display title, price, image & description.- Tailwind styling- Variant picker and buy now button- Bonus if there’s time: Collections page
Prerequisites: - A Chromium-based browser (StackBlitz)- Ideally experience with React. A general web development background would be fine.