Merge pull request #185 from NebulaServices/dev
Merge UV and Dynamic SW files
This commit is contained in:
commit
1b750df0f1
3 changed files with 32 additions and 36 deletions
|
|
@ -17,11 +17,8 @@
|
|||
<script>
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", () => {
|
||||
navigator.serviceWorker.register("/uvsw.js", {
|
||||
scope: __uv$config.prefix
|
||||
});
|
||||
navigator.serviceWorker.register("/dysw.js", {
|
||||
scope: __dynamic$config.prefix
|
||||
navigator.serviceWorker.register("/sw.js", {
|
||||
scope: "/~/"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
importScripts("/uv/uv.bundle.js");
|
||||
importScripts("/uv/uv.config.js");
|
||||
importScripts(__uv$config.sw || "/uv/uv.sw.js");
|
||||
importScripts("/dynamic/dynamic.config.js");
|
||||
importScripts("/dynamic/dynamic.worker.js");
|
||||
|
||||
const sw = new UVServiceWorker();
|
||||
const dynamic = new Dynamic();
|
||||
|
||||
self.dynamic = dynamic;
|
||||
|
|
@ -8,7 +12,7 @@ self.dynamic = dynamic;
|
|||
self.addEventListener("fetch", (event) => {
|
||||
if (
|
||||
event.request.url.startsWith(location.origin + self.__dynamic$config.prefix)
|
||||
)
|
||||
) {
|
||||
event.respondWith(
|
||||
(async function () {
|
||||
if (await dynamic.route(event)) {
|
||||
|
|
@ -18,4 +22,9 @@ self.addEventListener("fetch", (event) => {
|
|||
return await fetch(event.request);
|
||||
})()
|
||||
);
|
||||
} else if (
|
||||
event.request.url.startsWith(location.origin + __uv$config.prefix)
|
||||
) {
|
||||
event.respondWith(sw.fetch(event));
|
||||
}
|
||||
});
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
importScripts("/uv/uv.bundle.js");
|
||||
importScripts("/uv/uv.config.js");
|
||||
importScripts(__uv$config.sw || "/uv/uv.sw.js");
|
||||
|
||||
const sw = new UVServiceWorker();
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
if (event.request.url.startsWith(location.origin + __uv$config.prefix))
|
||||
return event.respondWith(sw.fetch(event));
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue