-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
60 lines (56 loc) · 1.66 KB
/
Copy pathsw.js
File metadata and controls
60 lines (56 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// sw.js - Service Worker for offline AI model caching
const CACHE_NAME = 'frenzy-chatbot-v1.2';
const STATIC_CACHE = 'static-cache-v1';
const AI_MODEL_CACHE = 'ai-model-cache-v1';
// Files to cache immediately
const STATIC_FILES = [
'/',
'/index.html',
'/style.css',
'/script.js',
'/frenzy.svg',
'/videos/desktop-video.mp4',
'/videos/light-video.mp4',
'/models/offline-ai-model.js' // We'll create this
];
// Install event - cache all static files and AI model
self.addEventListener('install', (event) => {
console.log('Service Worker installing...');
event.waitUntil(
caches.open(STATIC_CACHE)
.then((cache) => {
console.log('Caching static files');
return cache.addAll(STATIC_FILES);
})
.then(() => {
console.log('All files cached successfully');
return self.skipWaiting();
})
);
});
// Activate event - clean up old caches
self.addEventListener('activate', (event) => {
console.log('Service Worker activating...');
event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames.map((cacheName) => {
if (cacheName !== STATIC_CACHE && cacheName !== AI_MODEL_CACHE) {
console.log('Deleting old cache:', cacheName);
return caches.delete(cacheName);
}
})
);
}).then(() => self.clients.claim())
);
});
// Fetch event - serve from cache first, then network
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request)
.then((response) => {
// Return cached version or fetch from network
return response || fetch(event.request);
})
);
});