Commit 14420bf2 authored by Vincent Bechu's avatar Vincent Bechu

[erp5_officejs] Bootloader Service Worker, fetch from network when referrer is the scope

Allowed change cache to update application.
parent 8ab1add8
......@@ -25,6 +25,20 @@ var global = self, window = self;
});
}
function getFromLocal(relative_url) {
if (self.storage.get === undefined) {
self.storage = createStorage("ojs_source_code");
}
return self.storage.getAttachment(self.registration.scope, relative_url)
.push(function (blob) {
return new Response(blob, {
'headers': {
'content-type': blob.type
}
});
});
}
self.addEventListener('install', function (event) {
event.waitUntil(self.skipWaiting());
});
......@@ -43,33 +57,41 @@ var global = self, window = self;
event.respondWith(new Response(self.cache_list));
return;
}
event.respondWith(
new self.RSVP.Queue()
.push(function () {
if (self.storage.get === undefined) {
self.storage = createStorage("ojs_source_code");
}
return self.storage.getAttachment(self.registration.scope, relative_url)
.push(function (blob) {
return new Response(blob, {
'headers': {
'content-type': blob.type
else if (event.request !== undefined && event.request.referrer === self.registration.scope) {
event.respondWith(
new self.RSVP.Queue()
.push(function () {
return fetch(event.request);
})
.push(function (response) {
if (response.status === 200) {
return response;
}
return getFromLocal(relative_url);
})
.push(undefined, function (error) {
return new Response(error, {"statusText": error.message, "status": 500});
})
);
} else {
event.respondWith(
new self.RSVP.Queue()
.push(function () {
return getFromLocal(relative_url);
})
.push(undefined, function (error) {
if (error instanceof self.jIO.util.jIOError) {
if (relative_url.indexOf('http') === -1) {
if (self.cache_list.indexOf(relative_url) === -1) {
self.cache_list.push(relative_url);
}
});
});
})
.push(undefined, function (error) {
if (error instanceof self.jIO.util.jIOError) {
if (relative_url.indexOf('http') === -1) {
if (self.cache_list.indexOf(relative_url) === -1) {
self.cache_list.push(relative_url);
}
return fetch(event.request);
}
return fetch(event.request);
}
return new Response(error, {"statusText": error.message, "status": 500});
})
);
return new Response(error, {"statusText": error.message, "status": 500});
})
);
}
});
}(self, fetch, Request, Response));
\ No newline at end of file
......@@ -227,7 +227,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>961.10686.10882.5973</string> </value>
<value> <string>961.30858.43041.57309</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -245,7 +245,7 @@
</tuple>
<state>
<tuple>
<float>1502096517.05</float>
<float>1502980874.99</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment