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