You can embed a "backend" as a service worker and use htmx to interact with it.
A proof of concept here: https://github.com/richardanaya/wasm-service
A possible extension to HTMX would be to allow this kind of offloading to pure JS functions instead of requiring hacky intercepts.
You would still have a clear separation of responsibilities between frontend rendering (by the browser only) and application logic (which only generates HTML as output).