Phase 7c+7d: cache invalidation + offline data layer
7c: Client data cache management via element attributes (sx-cache-invalidate) and response headers (SX-Cache-Invalidate, SX-Cache-Update). Programmatic API: invalidate-page-cache, invalidate-all-page-cache, update-page-cache. 7d: Service Worker (sx-sw.js) with IndexedDB for offline-capable data caching. Network-first for /sx/data/ and /sx/io/, stale-while- revalidate for /static/. Cache invalidation propagates from in-memory cache to SW via postMessage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3551,6 +3551,27 @@ PLATFORM_ORCHESTRATION_JS = """
|
||||
});
|
||||
}
|
||||
|
||||
function parseSxData(text) {
|
||||
// Parse SX text into a data value. Returns the first parsed expression,
|
||||
// or NIL on error. Used by cache update directives.
|
||||
try {
|
||||
var exprs = parse(text);
|
||||
return exprs.length >= 1 ? exprs[0] : NIL;
|
||||
} catch (e) {
|
||||
logWarn("sx:cache parse error: " + (e && e.message ? e.message : e));
|
||||
return NIL;
|
||||
}
|
||||
}
|
||||
|
||||
function swPostMessage(msg) {
|
||||
// Send a message to the active service worker (if registered).
|
||||
// Used to notify SW of cache invalidation.
|
||||
if (typeof navigator !== "undefined" && navigator.serviceWorker &&
|
||||
navigator.serviceWorker.controller) {
|
||||
navigator.serviceWorker.controller.postMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
function urlPathname(href) {
|
||||
try {
|
||||
return new URL(href, location.href).pathname;
|
||||
@@ -4025,6 +4046,14 @@ def public_api_js(has_html, has_sx, has_dom, has_engine, has_orch, has_boot, has
|
||||
}
|
||||
// Set up direct resolution for future chunks
|
||||
global.__sxResolve = function(id, sx) { resolveSuspense(id, sx); };
|
||||
// Register service worker for offline data caching
|
||||
if ("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker.register("/sx-sw.js", { scope: "/" }).then(function(reg) {
|
||||
logInfo("sx:sw registered (scope: " + reg.scope + ")");
|
||||
}).catch(function(err) {
|
||||
logWarn("sx:sw registration failed: " + (err && err.message ? err.message : err));
|
||||
});
|
||||
}
|
||||
};
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", _sxInit);
|
||||
|
||||
Reference in New Issue
Block a user