Compare commits
3 commits
0d2cc5a354
...
8298e7d098
Author | SHA1 | Date | |
---|---|---|---|
|
8298e7d098 | ||
|
d9541fb2b0 | ||
|
20ea7787dc |
3 changed files with 36 additions and 35 deletions
|
@ -70,10 +70,10 @@
|
||||||
await navigator.serviceWorker.register("sw.js");
|
await navigator.serviceWorker.register("sw.js");
|
||||||
</script>
|
</script>
|
||||||
<p>Here is some example text</p>
|
<p>Here is some example text</p>
|
||||||
<form action="/light-dark-toggle" method="get">
|
<form action="./light-dark-toggle" method="get">
|
||||||
<input id="full-demo" type="submit" value="Fully enhanced demo">
|
<input id="full-demo" type="submit" value="Fully enhanced demo">
|
||||||
</form>
|
</form>
|
||||||
<form action="/light-dark-toggle" method="get">
|
<form action="./light-dark-toggle" method="get">
|
||||||
<input id="min-demo" type="submit" value="No javascript simulation">
|
<input id="min-demo" type="submit" value="No javascript simulation">
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -9,6 +9,7 @@ self.addEventListener("fetch", event =>{
|
||||||
const resp3 = resp2.clone();
|
const resp3 = resp2.clone();
|
||||||
const body = await resp2.text();
|
const body = await resp2.text();
|
||||||
const url = new URL(event.request.url);
|
const url = new URL(event.request.url);
|
||||||
|
console.log(url.pathname);
|
||||||
if(url.pathname.endsWith("light-dark-toggle")){
|
if(url.pathname.endsWith("light-dark-toggle")){
|
||||||
return await handle_redirect(event.request);
|
return await handle_redirect(event.request);
|
||||||
}
|
}
|
||||||
|
@ -24,13 +25,13 @@ async function handle_redirect(req){
|
||||||
const up_promise = new Promise((res)=>{
|
const up_promise = new Promise((res)=>{
|
||||||
db_req.onupgradeneeded = (event) => {
|
db_req.onupgradeneeded = (event) => {
|
||||||
const db = event.target.result;
|
const db = event.target.result;
|
||||||
IDB_cond_create(db, "light-dark-store", {}).then(res);
|
IDB_cond_create(db, "light-dark-store", {keyPath: 'id'}).then(res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const suc_promise = new Promise((res)=>{
|
const suc_promise = new Promise((res)=>{
|
||||||
db_req.onsuccess = (event) => {
|
db_req.onsuccess = (event) => {
|
||||||
const db = event.target.result;
|
const db = event.target.result;
|
||||||
const transaction = db.transaction("light-dark-store");
|
const transaction = db.transaction("light-dark-store", "readwrite");
|
||||||
transaction.oncomplete = res;
|
transaction.oncomplete = res;
|
||||||
|
|
||||||
transaction.objectStore("light-dark-store", "readwrite");
|
transaction.objectStore("light-dark-store", "readwrite");
|
||||||
|
@ -88,7 +89,7 @@ async function handle_html(req, resp, body){
|
||||||
const transaction = db.transaction("light-dark-store");
|
const transaction = db.transaction("light-dark-store");
|
||||||
transaction.oncomplete = res;
|
transaction.oncomplete = res;
|
||||||
|
|
||||||
const obj_store = transaction.objectStore("light-dark-store", "read");
|
const obj_store = transaction.objectStore("light-dark-store", "readonly");
|
||||||
const grab = obj_store.get(1);
|
const grab = obj_store.get(1);
|
||||||
grab.onsuccess = (event) => {res(!!event.result)};
|
grab.onsuccess = (event) => {res(!!event.result)};
|
||||||
};
|
};
|
||||||
|
|
60
sw.js
60
sw.js
|
@ -1,30 +1,30 @@
|
||||||
"use strict";
|
//"use strict";
|
||||||
|
//
|
||||||
// used so I can prompt updates to the service worker
|
//// used so I can prompt updates to the service worker
|
||||||
const version = "22-01-2025";
|
//const version = "22-01-2025";
|
||||||
|
//
|
||||||
const cache = new Cache();
|
//const cache = new Cache();
|
||||||
|
//
|
||||||
self.addEventListener("install", (event) => {
|
//self.addEventListener("install", (event) => {
|
||||||
// can't add /static/* due to demos living there
|
// // can't add /static/* due to demos living there
|
||||||
cache.addAll([
|
// cache.addAll([
|
||||||
"/",
|
// "/",
|
||||||
"/index.html",
|
// "/index.html",
|
||||||
"/static/css/*",
|
// "/static/css/*",
|
||||||
"/static/js/*",
|
// "/static/js/*",
|
||||||
"/static/images/*",
|
// "/static/images/*",
|
||||||
"/static/video/*"
|
// "/static/video/*"
|
||||||
]);
|
// ]);
|
||||||
});
|
//});
|
||||||
|
//
|
||||||
async function handleCache(event) {
|
//async function handleCache(event) {
|
||||||
const cache_value = await cache.match(event.request);
|
// const cache_value = await cache.match(event.request);
|
||||||
if (cache_value === undefined) {
|
// if (cache_value === undefined) {
|
||||||
return fetch(event.request);
|
// return fetch(event.request);
|
||||||
}
|
// }
|
||||||
return cache_value;
|
// return cache_value;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
self.addEventListener("fetch", async (event) => {
|
//self.addEventListener("fetch", async (event) => {
|
||||||
event.respondWith(handleCache(event));
|
// event.respondWith(handleCache(event));
|
||||||
});
|
//});
|
||||||
|
|
Loading…
Reference in a new issue