HTMZ a Back-End Driven Hypermedia Approach

Note: This site requires a browser which supports Service Workers.

Introduction

HTMZ is a minimalist HTML microframework for creating interactive and modular web user interfaces with the familiar simplicity of plain HTML. This is an "extension" that I have made to make it even more powerful and flexible.

Features:

Documentation

This implementation of HTMZ uses four APIs to determine how the updates are applied.

id
The id attribute matches the element that will be updated. It replaces the original element with the new content. This is the simplicist and easiest way to perform updates.
hz-target
uses the query selector to determine what element to update.
hz-swap
determines how the content is inserted. There are four different values which can be used:
replaceWith
replaces the original element with the new content (default). In practice this never needs to be explicit.
append
appends the content to the end of the target element
prepend
prepends the content to the beginning of the target element
before
inserts the content before the target element
after
inserts the content after the target element
template
When you do not have a root HTML element use the template element. This is useful for inserting table rows, list items, and other elements that do not have a single root element. When you return an empty template it will delete the old the element it is replacing when you use the strategy replaceWith (which is default).

Examples

Simple Todo

This example shows a simple todo list implementation using HTMZ.

Original Code
HTML Response No data has been returned yet.

Dynamic Table

This example demonstrates dynamic table row addition using HTMZ. Note that the table elements need to be wrapped in <template> tags.

Original Code
HTML Response
No data has been returned yet.

Replace a link with new content.

Original Code
HTML Response
No data has been returned yet.

Get secret message.

Limitations

There are some drawbacks to doing it this one. One of those is that you cannot make two API calls simultaneously. If you find you need to, then either using a different library or create multiple iFrames.

Take as an example the two links below. When you click the button it will click the two links simultaneously. But only one completes. In practice this shouldn't happen very often or ever in a real application. But if your application does require multiple API calls then perhaps your application is too complex for this library. Or maybe you could combine the API calls. This could also be a good thing as it prevents forms from being called twice automatically.

Original Code
HTML Response
No data has been returned yet.

Get secret message 1. Get secret message 2.

Advanced Usage

For advanced usage please refer to my soccer application. It shows that you can create rather complex web applications with this pattern, including offline first PWA with highly dynamic data.

Features