Hc declares dynamic web pages by using HTML data attributes to seamlessly update the page with HTML fragments requested from the server.
Using hypertext as the interaction substrate keeps logic on the server and, in the simplest cases, reduces front-end client code to custom CSS animations and an invocation of the Hc_page.init
function.
hc
was inspired by htmx.
If you really do not want to write a single line of front-end code, include the page $(opam var share)/hc/hc-page.js
in your page. Now the following:
<script type="text/javascript" defer src="hc-page.js"></script> <button data-request="POST /clicked" data-effect="element">Replace me</button>
instructs a click on the button to perform a POST request to /clicked
and replace the button with the HTML response. That's it.
If you installed hc
with tests (opam install -t hc
). The hc-examples
binary serves a few interaction examples.
Hc
behaviour itself, this allows to chain Hc
connections in interesting ways and helps coordinating with other front end code. Update. Something was hastily added in Hc
.Ev. needs proper design and documentation.data-preserve
attribute which patches by id in the replacementdata-push-history
, pushes the request url, snapshots body element for state restoration.from:<sel>
).data-response-sel
to apply on the response.hc
use it.Referrer-Policy
for requests. For now we use same-origin
. Possibly allow to set referer
.