htmx 2 Released - The Next Big Thing?
Written by Ian Elliot   
Wednesday, 19 June 2024

htmx seems to have crept up on us programmers - perhaps because we are programmers. Is this the next big thing and is it a JavaScript killer?

It has been quiet on the web development front for a while - or so it seems to me. After the reinvention of HTML and JavaScript in the form of HTML 5 (remember that?) and ECMAScript 6, nothing much has happened. We seem to have gravitated towards higher level frameworks such as React or Angular but now we have something new and it looks as if HTML might take over from JavaScript.

htmx

The idea behind htmx is that, by extending what tags can do, markup can do things that would previously would have have required Ajax and JavaScript. The basic idea is to extend the function of the anchor tag to other tags. The anchor tag allows you to specify a URL which is downloaded and the HTML is displayed if the user clicks on it. The generalization is to allow any tag to download any

thing and incorporate it into the page in response to an event.

For example:

<button hx-get="https://myWebsite/myList" 
hx-target="#result">
Load Data
</button>
<div id="result"></div>

This creates a button which, when clicked, downloads myList and adds its HTML to the element with id result, i.e. the div. Once seen this is obvious and you should be saying "why didn't I think of this before". Of course, behind the scenes all that happens is that an Ajax call is made and some JavaScript inserts the retrieved HTML into the designated tag - but no JavaScript had to be written.

As the htmx website states:

  • Now any element, not just anchors and forms, can issue an HTTP request
  • Now any event, not just clicks or form submissions, can trigger requests
  • Now any HTTP verb, not just GET and POST, can be used
  • Now any element, not just the entire window, can be the target for update by the request

This seems like a good idea, but what is not apparent until you start working with it is how much it can achieve without additional JavaScript. It is easy to understand and hence quick to learn and you quickly see how to do things that otherwise would have involved code.

htmx has its roots in intercooler.js, a frontend library created by Carson Gross in 2013.  Now we have version 2, the first update since 2020 and the good news, I suppose, is that there are no major changes. Perhaps the headline news is that it no longer supports Internet Explorer and this seems reasonable. There has also been a major reorganization of extensions into their own repos, but the older extensions are still available. A potentially breaking change is to the hx-on attribute which has been significantly simplified.

You might be wondering if this could be HTML 6 and Carson Gross commented in a Hacker News thread in response to a question if htmx could be built into the browser:

yes, there are, alex petros, an htmx maintainer, gave a talk at Big Sky Dev Con on the shortest path to htmx-like functionality in HTML here: https://www.youtube.com/watch?v=inRB6ull5WQ

we are talking w/the chrome developers about these ideas, i'm cautiously optimistic

Of course, we would all prefer that it wasn't a Chrome-only extension, but what goes into Chrome often becomes part of the standard, for obvious reasons.

Is this a JavaScript killer?

Probably not, as it takes a lot to kill any previously adopted technology and at the moment it is a JavaScript technology. The answer might be different if the idea is adopted as a basic HTML attribute.

Is this a framework killer?

It could be. The point is that it takes time to learn a framework and they keep changing. If your requirement is simple then why bother with a framework. HTML and htmx plus a little JavaScript glue might be all you need.

Finally I should mention that the idea of htmx is closely related to the idea of converting HTML into a true hypertext language. The haiku on the website states it perfectly:

javascript fatigue:
longing for a hypertext
already in hand

 htmxicon

More Information

https://htmx.org/

Related Articles

JavaScript Turns 25

How Is JavaScript Doing?

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


Code Assessment Added To .NET Upgrade Assistant
01/07/2024

Microsoft has improved the .NET Upgrade Assistant to add code assessment features. The assistant helps Visual Studio developers upgrade .NET applications to the latest version of .NET.



Andrew Tanenbaum Gains ACM Award
28/06/2024

Andrew Tanenbaum has been awarded the 2023 ACM System Software Award for MINIX the operating system he created for teaching purposes and which was an important influence on Linux.


More News

kotlin book

 

Comments




or email your comment to: comments@i-programmer.info

 

<ASIN:1871962528>

<ASIN:1871962579>

Last Updated ( Wednesday, 19 June 2024 )