Skip to content

[Feature] PWA Service Worker Integration for Offline WASM Caching #10

@HaHiepThanh

Description

@HaHiepThanh

📋 Context & Problem Description

A primary drawback of Go-WASM applications is the size of the initial file download (app.wasm is 1.7 MB - 4.1 MB raw). Even though it compresses well with gzip/Brotli, a first-time loading latency exists over mobile networks. Furthermore, reload operations on unstable networks may reload files unnecessarily if standard browser caching policies expire or are ignored.

💡 Proposed Solution & Implementation Plan

Provide native Progressive Web App (PWA) and Service Worker support:

  1. Automatic Service Worker Generation:
    Extend the Gutter build tool (gutter build) to automatically generate a service-worker.js file in the output directory.
  2. Offline Caching Strategy:
    • Configure the Service Worker with a Cache-First strategy targeting static assets (app.wasm, wasm_exec.js, styling sheets, static images).
    • After the very first load, app.wasm is served directly from the local browser Cache storage, reducing reload times to 0ms network cost.
  3. Background Updates:
    • When a new version of the app is built and deployed, the Service Worker detects the hash change in manifest.json.
    • It fetches the updated .wasm file in the background, prompting the user with an "update available" toast to refresh and apply the update.

🎯 Impact & Benefits

  • Instant Load Times: Sub-10ms subsequent load times, bypassing network latency completely.
  • Offline Capability: Enables full offline execution of Gutter apps, matching native application characteristics.

🏷️ Suggested Labels

feature, performance, cli

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions