What is HTMX?
Understanding the spirit of the HTMX library
Not only has ASP.NET Core seen improvements over the last several years, but the underlying .NET Framework's performance continues to improve and provides a compelling foundation beyond web development. .NET has production-tested integrations with databases, third-party services, and NuGet packages that make developing server-side solutions a breeze. ASP.NET Core developers will likely be big proponents of Razor, which allows us to combine the C# programming language with HTML structures. Finally, We can host all these technologies on beefy servers to perform complex and process-intensive tasks. So what does this pretext have to do with HTMX?
General motivations behind HTMX include:
- Any DOM element can trigger an HTTP request.
- Additional HTTP methods can be used in addition to GET and POST.
- An interaction results in an HTML response used to update the existing UI.
- State management is accomplished server-side, with responses reflecting state in HTML payloads.
If this sounds appealing to you, please continue, I promise you won't be disappointed.
I've provided a sample project available on GitHub for folks who want to follow along. We will use .NET 6, but all techniques and approaches should work on prior versions. The samples use Razor pages, but the server-side technology is swappable for any tech you prefer. We are also using Bootstrap 5, but HTMX is design library agnostic; I just wanted to make the samples look nice for you. Finally, we'll be using HTMX.NET, an optional library I developed to enhance the ASP.NET Core and HTMX experience.
This video series will show techniques ASP.NET Core developers can utilize to enhance existing web applications. Like most technologies, there is always more than one solution. As you go through this video series and learn more, think about how you may solve previous examples in new ways.
Let's look at our first example, the obligatory "Hello World"!