-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsw.js
More file actions
95 lines (89 loc) · 2.29 KB
/
sw.js
File metadata and controls
95 lines (89 loc) · 2.29 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const CACHE_NAME = 'my-note-app-cache-v9';
const urlsToCache = [
'/',
'/index.html',
'/CSS/index.css',
'/CSS/signup.css',
'/CSS/styles.css',
'/HTML/signup.html',
'/JS/vendor/lz-string.min.js',
'/JS/vendor/qrcode.min.js',
'/JS/aiAssistant.js',
'/JS/audioRecorder.js',
'/JS/authButtons.js',
'/JS/authPage.js',
'/JS/constants.js',
'/JS/db.js',
'/JS/eventHandlers.js',
'/JS/exportImport.js',
'/JS/filterSearchSort.js',
'/JS/folderManager.js',
'/JS/formattingToolbar.js',
'/JS/geminiAPI.js',
'/JS/layoutManager.js',
'/JS/loginPage.js',
'/JS/mailFeature.js',
'/JS/mediaManager.js',
'/JS/noteManager.js',
'/JS/noteOperations.js',
'/JS/notesApp.js',
'/JS/profileManager.js',
'/JS/renderer.js',
'/JS/shapeManager.js',
'/JS/sketchPad.js',
'/JS/slashCommands.js',
'/JS/smartCalendar.js',
'/JS/storage.js',
'/JS/themeManager.js',
'/JS/themePresets.js',
'/JS/utilities.js',
'/manifest.json'
];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
self.skipWaiting(); // Force activate new SW immediately
});
self.addEventListener('fetch', event => {
// NETWORK FIRST STRATEGY (Critical for development/updates)
// Try network first, fall back to cache if offline
event.respondWith(
fetch(event.request)
.then(response => {
// Check if we received a valid response
if (!response || response.status !== 200 || response.type !== 'basic') {
return response;
}
// Clone the response
var responseToCache = response.clone();
caches.open(CACHE_NAME)
.then(cache => {
cache.put(event.request, responseToCache);
});
return response;
})
.catch(() => {
// If network fails, try cache
return caches.match(event.request);
})
);
});
self.addEventListener('activate', event => {
const cacheWhitelist = [CACHE_NAME];
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheWhitelist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});