Summary
A developer shares hands-on experience building web applications with go-app, a Go framework that compiles to WebAssembly (WASM). Four key lessons are summarized. First, caching is the primary enemy: Service Workers (sw.js) and browsers cache WASM files aggressively, so developers must bump the SW version number and append timestamp query parameters to WASM URLs in HTML to force refreshes. Second, component instances persist in SPA mode: when routing or changing global state such as themes, the root App component will reset child state (e.g., a saved search query) unless page instances are cached in a map[string]app.Composer, because returning new literals like &SearchPage{} in Render recreates components each time. Third, ctx.Update() is essential: in OnInput, OnClick, or asynchronous ctx.Dispatch callbacks, UI updates only appear when ctx.Update() is explicitly called; otherwise DOM changes are not detected even though WASM memory variables changed. Fourth, a distributed search backend requires a full P2P chain: WordHash generation, DHT selection to locate nodes, RemoteSearcher to issue requests, and an Aggregator to merge results. These notes are practical guidance for teams adopting go-app and WASM for client-side Go web development.
Experience Summary: The Four Key Lessons of go-app + WASM Development
This post summarizes hands-on experience developing with the go-app framework (Go compiled to WebAssembly):
1. Caching is enemy #1: The Service Worker (sw.js) and browsers cache WASM files very deeply. You must force refreshes by bumping the SW version number and adding a timestamp parameter to WASM URLs in the HTML.
2. Component instance persistence: In SPA applications, when the root App component switches routes or modifies global state (e.g., themes), the Render method returning fresh literals each time (such as &SearchPage{}) will instantly reset previous state (such as s.Query) unless you manually cache page instances using map[string]app.Composer.
3. ctx.Update() is the key to re-rendering: 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 perceive the change.
4. Backend P2P chain: Distributed search requires a complete backend chain: WordHash generation -> DHT Selection to locate nodes -> RemoteSearcher to issue requests -> 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