blob: d2be9573b7cda6350b1a66ad61b88456667b74aa (
plain)
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
|
var prefix = "/tests/dom/workers/test/serviceworkers/fetch/origin/";
function addOpaqueRedirect(cache, file) {
return fetch(new Request(prefix + file, { redirect: "manual" })).then(function(response) {
return cache.put(prefix + file, response);
});
}
self.addEventListener("install", function(event) {
event.waitUntil(
self.caches.open("origin-cache")
.then(c => {
return Promise.all(
[
addOpaqueRedirect(c, 'index.sjs'),
addOpaqueRedirect(c, 'index-to-https.sjs')
]
);
})
);
});
self.addEventListener("fetch", function(event) {
if (event.request.url.indexOf("index-cached.sjs") >= 0) {
event.respondWith(
self.caches.open("origin-cache")
.then(c => {
return c.match(prefix + 'index.sjs');
})
);
} else if (event.request.url.indexOf("index-to-https-cached.sjs") >= 0) {
event.respondWith(
self.caches.open("origin-cache")
.then(c => {
return c.match(prefix + 'index-to-https.sjs');
})
);
} else {
event.respondWith(fetch(event.request));
}
});
|