-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsw.js
32 lines (29 loc) · 1.15 KB
/
sw.js
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
var APP_PREFIX = 'ApplicationName_' // Identifier for this app (this needs to be consistent across every cache update)
var VERSION = 'version_01' // Version of the off-line cache (change this value everytime you want to update cache)
var CACHE_NAME = APP_PREFIX + VERSION
var URLS = [ // Add URL you want to cache in this list.
'/SWTest/', // If you have separate JS/CSS files,
'/SWTest/index.html' // add path to those files here
]
let outgoingPort;
self.addEventListener('message', function (e) {
if (e.data && e.data.type === 'INIT_PORT') {
outgoingPort = e.ports[0];
}
});
// Respond with cached resources
self.addEventListener('fetch', function (e) {
if (outgoingPort) {
outgoingPort.postMessage({ message: " fetch: " + e.request });
}
if (e.request.url.includes("testImage.jpg")) {
let newRequest = new Request("https://paultiarks.github.io/SWTest/testImageTwo.jpg")
e.respondWith(fetch(newRequest))
}
})
// Delete outdated caches
self.addEventListener('activate', function (e) {
if (outgoingPort) {
outgoingPort.postMessage({ message: "activated" });
}
})