mirror of
https://github.com/theodore-song/polymarket-analyst.git
synced 2026-08-19 18:48:10 +00:00
Add adaptive offline agent engine
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
const CACHE_NAME = "polymarket-arena-v35";
|
||||
const APP_SHELL = ["/", "/index.html", "/personal.html"];
|
||||
|
||||
self.addEventListener("install", event => {
|
||||
event.waitUntil(caches.open(CACHE_NAME).then(cache => cache.addAll(APP_SHELL)).then(() => self.skipWaiting()));
|
||||
});
|
||||
|
||||
self.addEventListener("activate", event => {
|
||||
event.waitUntil(caches.keys()
|
||||
.then(keys => Promise.all(keys.filter(key => key !== CACHE_NAME).map(key => caches.delete(key))))
|
||||
.then(() => self.clients.claim()));
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", event => {
|
||||
if(event.request.method !== "GET") return;
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
if(event.request.mode === "navigate") {
|
||||
event.respondWith(fetch(event.request)
|
||||
.then(response => {
|
||||
const copy = response.clone();
|
||||
caches.open(CACHE_NAME).then(cache => cache.put(event.request, copy));
|
||||
return response;
|
||||
})
|
||||
.catch(async () => (await caches.match(event.request)) || (await caches.match("/index.html"))));
|
||||
return;
|
||||
}
|
||||
|
||||
if(url.origin === self.location.origin && !url.pathname.startsWith("/api/")) {
|
||||
event.respondWith(caches.match(event.request).then(cached => cached || fetch(event.request).then(response => {
|
||||
const copy = response.clone();
|
||||
caches.open(CACHE_NAME).then(cache => cache.put(event.request, copy));
|
||||
return response;
|
||||
})));
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user