Hypermedia foundations
Add HTMX to a page
Load HTMX 2 from a CDN or install it as a package, then verify the file is delivered before adding attributes.
For a page without a JavaScript build step, load the latest HTMX 2.x release:
<script
src="https://cdn.jsdelivr.net/npm/htmx.org@2/dist/htmx.min.js">
</script>
The @2 part keeps the URL on HTMX 2 while allowing patch and minor updates.
In a project with an asset pipeline, install htmx.org@2 and import the appropriate distribution entry. Your lockfile records the exact version used by the project.
Before adding attributes, open the browser Network panel and confirm the script returns 200. Then run htmx.version in the console. If it is undefined, fix loading first; changing hx-* markup cannot repair a missing library.
Avoid an unversioned CDN URL. A future major release could introduce breaking changes.
Lesson completed