LearnNewsExamplesServices
Frontmatter
id8759
titleServiceWorker: Enforce Network-First Strategy for Config Files
stateClosed
labels
bugaicore
assigneestobiu
createdAtJan 17, 2026, 6:01 PM
updatedAtJan 17, 2026, 6:06 PM
githubUrlhttps://github.com/neomjs/neo/issues/8759
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 17, 2026, 6:06 PM

ServiceWorker: Enforce Network-First Strategy for Config Files

Closed v11.23.0 bugaicore
tobiu
tobiu commented on Jan 17, 2026, 6:01 PM

Description

The Service Worker update strategy currently relies on version checks in the app layer (DefaultConfig, neo-config.json). If these configuration files are served from the browser cache (stale v1) while the Service Worker has updated (v2), the handshake fails, causing a reload loop.

To fix this, we need to enforce a "Network First" strategy for these critical configuration files. This ensures the app always receives the latest version-stamped config, allowing the handshake to succeed or fail correctly based on the actual server state, not stale cache.

Tasks

  1. Modify src/worker/ServiceBase.mjs:
    • Add networkFirstPaths config/property containing ['neo-config.json', 'DefaultConfig.mjs'].
    • Update onFetch to check this list before the standard cachePaths logic.
    • Implement the "Network First" strategy:
      • Try fetch(request) first.
      • If successful: Update cache, return response.
      • If failed (offline): Return cache.match(request).

Acceptance Criteria

  • neo-config.json and DefaultConfig.mjs requests always attempt a network fetch first.
  • Offline support is preserved (fallback to cache works).
  • Reload loops caused by stale cached configs are eliminated.
tobiu added the bug label on Jan 17, 2026, 6:01 PM
tobiu added the ai label on Jan 17, 2026, 6:01 PM
tobiu added the core label on Jan 17, 2026, 6:01 PM
tobiu referenced in commit 15a9a1e - "fix: Enforce Network-First strategy for config files to prevent SW update loops (#8759)" on Jan 17, 2026, 6:06 PM
tobiu
tobiu Jan 17, 2026, 6:06 PM

Input from Gemini 3 Pro:

✦ I have implemented the Network-First strategy for DefaultConfig.mjs and neo-config.json in src/worker/ServiceBase.mjs.

Changes:

  1. Added networkFirstPaths: Defined a list of critical config files.
  2. Updated onFetch: Implemented a priority check for these paths.
    • It attempts to fetch with {cache: 'reload'} to bypass the browser cache.
    • On success, it updates the Service Worker cache (for offline capability) and returns the fresh response.
    • On failure (offline), it falls back to the cache.
  3. Documentation: Added detailed JSDoc explaining the "Reload Loop" prevention strategy.

This ensures the App Worker always sees the true server version during the handshake, preventing false mismatches caused by stale browser caches.

tobiu assigned to @tobiu on Jan 17, 2026, 6:06 PM
tobiu closed this issue on Jan 17, 2026, 6:06 PM