runtimeassets

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package runtimeassets is the single registry + HTTP handler for the Gothic framework's WASM-runtime assets that used to be COPIED into every project's public/ folder at `gothic init` / build time. Instead of shipping bytes into the user's tree, the framework now serves them straight from its own embed under a dedicated route prefix (/_gothic/), so a framework upgrade updates the runtime for every project with no file churn and no stale copies.

The runtime assets served here:

gothic-core.js              the shared idempotent client runtime (gothiccore, minified)
gothic-core.wasm            the prebuilt full-Go static core module (corewasm)
gothic-core-exec.js         the standard-Go wasm_exec shim matched to the core (corewasm)
gothic-core-boot.js         the generated core boot loader (corewasm)
wasm_exec.js                the TinyGo wasm_exec shim (wasmexec)
htmx.min.js                 HTMX, self-hosted (vendorjs) — no longer a render-blocking CDN <script>
amz-content-sha256.min.js   the amz-content-sha256 HTMX extension (vendorjs)

Every asset is content-negotiated: the handler precompresses each one with brotli and gzip at startup and serves the smallest form the client accepts (Content-Encoding: br|gzip), falling back to the raw bytes. This is what makes the ~1.9 MB gothic-core.wasm transfer at a fraction of its size on routes that serve it through this handler (a CDN in front is free to keep doing its own compression too).

NOTE the user's own GOROOT-matched wasm_exec_go.js stays in public/ (it is version-tied to the user's Go toolchain, copied at build time — not a framework artifact) and the per-page user WASM binaries stay under /public/wasm/.

This is a LEAF package over the asset-owning leaf packages (gothiccore, corewasm, wasmexec, vendorjs). Those packages must NOT import runtimeassets or a cycle forms — runtimeassets sits one level above them.

Index

Constants

View Source
const Prefix = "/_gothic/"

Prefix is the route namespace the framework serves its runtime assets under. It is deliberately distinct from /public/ so it never collides with a user's static files and can carry its own edge-cache behavior at the CDN.

Variables

This section is empty.

Functions

func Handler

func Handler() http.Handler

Handler serves the runtime assets under Prefix. It strips the prefix, looks the file up in the registry, sets the right Content-Type, marks it immutable when a ?v= cache-buster is present (mirroring immutableCacheMiddleware), negotiates a compressed encoding from Accept-Encoding, and writes the bytes. Unknown names 404. Only GET/HEAD are meaningful; other methods 405.

func Path

func Path(name, version string) string

Path returns the referencing URL for an asset name: Prefix+name+"?v="+version.

Types

type Asset

type Asset struct {
	Name        string
	Bytes       []byte // identity (uncompressed)
	Brotli      []byte // brotli-compressed, or nil if not smaller than Bytes
	Gzip        []byte // gzip-compressed, or nil if not smaller than Bytes
	ContentType string
	Version     string
}

Asset is one served runtime file: its basename (the path segment after the prefix), the raw bytes, precompressed brotli/gzip variants (nil when a variant is not smaller than the raw bytes), its Content-Type, and the content-hash used as the ?v= cache-buster in the URL that references it.

func All

func All() []Asset

All returns every registered asset (unordered).

func Get

func Get(name string) (Asset, bool)

Get returns the asset registered under name (the path segment after Prefix), and whether it exists.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL