❯ go-clikit
v0.10.0 pkg.go.dev ↗

packages › local web › localweb/htmx

htmx

import "github.com/GSI-HPC/go-clikit/localweb/htmx"

The scripts of a local page, htmx, its SSE extension and idiomorph, byte for byte as their projects publish them.

since v0.9.0 imports: no package of the kit decisions 35 · 41
The place of localweb/htmx in go-clikit: the packages it imports, and the packages that import it.termtextprogressdisplaycliprogressprogresstestmcpprogresseventlogfanoutfanouttestclioutdoctorfsutilcobratreecobratreetestlocalwebsessionsselocalwebtestlaunchassetspagehtmx

The package holds the scripts that a local web page of the kit runs: htmx, its extension for Server-Sent Events, and idiomorph, which swaps a fragment by changing only what changed. They are the files their projects publish, byte for byte, under the Zero-Clause BSD licence. A test holds each to its checksum.

vendor, err := assets.New(htmx.Files(), "/htmx/", assets.Options{})
if err != nil {
	fmt.Println(err)
	return
}
mux := http.NewServeMux()
mux.Handle("GET /htmx/", vendor)

target := vendor.URL(htmx.Script)
fmt.Println(strings.HasPrefix(target, "/htmx/"), strings.HasSuffix(target, "/htmx.min.js"))

w := httptest.NewRecorder()
mux.ServeHTTP(w, httptest.NewRequest(http.MethodGet, target, nil))
fmt.Println(w.Code, w.Header().Get("Content-Type"))
fmt.Println(htmx.Config)
true true
200 text/javascript; charset=utf-8
{"allowEval":false,"allowScriptTags":false,"includeIndicatorStyles":false,"selfRequestsOnly":true,"historyCacheSize":0,"historyRestoreAsHxRequest":false}
Example in localweb/htmx/example_test.go. CI runs it and checks its output.

Serve them with assets, and put htmx.Config into the page, so that htmx keeps to the Content-Security-Policy of localweb.Headers.

NameWhat it is
htmx.Filesthe scripts, as an fs.FS
htmx.Configthe htmx-config of the page; it restores history as a page (decision 41)
htmx.ScriptVersion, htmx.SSEVersion, htmx.MorphVersionthe versions of the scripts

A new version of a script comes in a minor release of the kit.