runtime

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package runtime provides the GoFastr client-side JavaScript runtime as an embedded resource. The runtime handles event delegation, component hydration on first interaction, and SSE listeners for server-driven islands.

Use RuntimeJS() to get the JavaScript source as a string, or RuntimeSize() to check the size of the runtime.

Package runtime ships the framework's client-side JavaScript runtime.

Two surfaces are exposed:

  • The bundled runtime (`runtime.js`) — the one-script payload that handles every framework primitive (dispatchRPC, SPA router, screen cache, signals, widgets, etc). Served at `/__gofastr/runtime.js`. This is the default surface.

  • Per-module bundles (`src/<name>.js`) — small payloads loaded on demand via `__gofastr.loadModule(name)`. Used for the optional code-splitting path; pages opt into individual modules instead of the bundled runtime when bundle size matters.

The HTTP server (core-ui/widget/server.go) consumes Module(name) + ModuleNames() to wire `/__gofastr/runtime/<name>.js` routes; the uihost emits `<link rel="modulepreload">` tags per page based on the components rendered on it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorSchemeJS

func ColorSchemeJS() (string, error)

ColorSchemeJS returns the color-scheme bootstrap script — a tiny synchronous snippet meant to ship at the TOP of <head> so dark-mode CSS tokens take effect during the same first paint that hits the page. Reads localStorage("gofastr.colorScheme") + the OS prefers-color-scheme hint, then sets <html data-color-scheme="…"> and a matching <meta name="color-scheme">.

Apps that ship a theme toggle call `window.__gofastr_colorScheme.set('auto'|'light'|'dark')` to override the OS preference.

func DemandLoadModuleNames

func DemandLoadModuleNames() []string

DemandLoadModuleNames returns the unique sorted list of every module referenced by the demand-load table. Used by tests to verify every declared module actually has a corresponding src/<name>.js file.

func Module

func Module(name string) (string, bool)

Module returns the source of a single split runtime module by name (e.g. "fileupload"). Used by the HTTP server to serve /__gofastr/runtime/<name>.js. Returns "", false when the module is not embedded. Minified on first read (cached).

func ModuleNames

func ModuleNames() []string

ModuleNames returns the sorted list of split modules currently embedded. Each name maps 1:1 to a /__gofastr/runtime/<name>.js URL.

func ModuleSize

func ModuleSize(name string) int

ModuleSize returns the byte size of a single embedded module, or 0 if the module isn't present. Used by tests asserting per-module size budgets.

func MustRuntimeJS

func MustRuntimeJS() string

MustRuntimeJS returns the bundled runtime or panics.

func NeededModules

func NeededModules(pageHTML string) []string

NeededModules returns the deduplicated, sorted list of demand-load runtime modules whose marker substring appears in pageHTML. Used by the framework's UI host to emit <link rel="modulepreload"> tags in <head> per page, kicking off module fetches in parallel with the initial paint.

Matches are substring containment — not a real HTML parse. The markers are unambiguous attribute prefixes ("data-fui-*"), so false positives are vanishingly rare and the cost of a false positive is one wasted module fetch (no correctness impact).

func RuntimeJS

func RuntimeJS() (string, error)

RuntimeJS returns the bundled runtime — the single-file IIFE every page ships by default. Minified on first call (or returned verbatim when RUNTIME_NOMINIFY=1).

func RuntimeSize

func RuntimeSize() int

RuntimeSize returns the byte size of the bundled runtime.

Types

This section is empty.

Directories

Path Synopsis
Package minify implements a token-aware JavaScript minifier used to shrink the embedded runtime sources before they're served.
Package minify implements a token-aware JavaScript minifier used to shrink the embedded runtime sources before they're served.

Jump to

Keyboard shortcuts

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