Summary
A developer shares four practical lessons from building applications with go-app, a Go framework that compiles to WebAssembly. First, caching is the top enemy: the Service Worker (sw.js) and browser caching of WASM files is deep, so you must bump SW version numbers and append timestamp query parameters to WASM URLs in HTML to force refreshes. Second, component instance persistence matters in SPAs: when routing or changing global state (like themes), returning new component literals (e.g., &SearchPage{}) from Render without manually caching page instances via map[string]app.Composer instantly resets prior state such as search queries. Third, ctx.Update() is the key to UI refresh: in OnInput, OnClick, or async ctx.Dispatch callbacks, you must explicitly call ctx.Update(), otherwise DOM changes will not be reflected even when WASM memory variables change. Fourth, a distributed search backend requires a complete P2P chain: WordHash generation, DHT Selection to locate nodes, RemoteSearcher to issue requests, and an Aggregator to merge results.
go-app Framework Development Experience
Lessons learned from building apps with the go-app framework and WebAssembly (WASM):
1. Caching Is Enemy Number One
Service Worker (
sw.js) and browser caching of WASM files is extremely deep. You must:
- Update the Service Worker version number
- Append timestamp parameters to WASM URLs in the HTML to force refreshes
2. Component Instance Persistence
In an SPA, when switching routes or changing global state (e.g., theme), the root
App component must manually cache page instances (using
map[string]app.Composer). Otherwise, the new literals returned by
Render each time (e.g.,
&SearchPage{}) will instantly reset previously held state (such as
s.Query).
3. ctx.Update() Is the Key to Refreshing
In
OnInput,
OnClick, or asynchronous
ctx.Dispatch callbacks, you must explicitly call
ctx.Update(). Otherwise, even if variables in WASM memory have changed, the DOM will not reflect the changes.
4. Backend P2P Chain
Distributed search requires a complete backend chain:
1.
WordHash generation
2.
DHT Selection to locate nodes
3.
RemoteSearcher to issue requests
4.
Aggregator to merge results
This page is an English static mirror generated for search and AI citation.
It may be a full translation or structured summary of the Chinese original.
Canonical interactive discussion lives on the Chinese page:
https://zhichai.net/topic/176922642