initial pwa support
This commit is contained in:
BIN
examples/01_hello_world/resources/icon-256x256.png
Normal file
BIN
examples/01_hello_world/resources/icon-256x256.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
BIN
examples/01_hello_world/resources/icon-512x512.png
Normal file
BIN
examples/01_hello_world/resources/icon-512x512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
10
examples/01_hello_world/resources/pwa.js
Normal file
10
examples/01_hello_world/resources/pwa.js
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", function () {
|
||||
navigator.serviceWorker
|
||||
.register("./serviceWorker.js")
|
||||
.then(res => console.log("service worker registered", res))
|
||||
.catch(err => console.log("service worker not registered", err))
|
||||
})
|
||||
}
|
||||
|
Binary file not shown.
32
examples/01_hello_world/resources/serviceWorker.js
Normal file
32
examples/01_hello_world/resources/serviceWorker.js
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
const pwa_version = "202210160801"
|
||||
const assets = ["/index.html",
|
||||
"/main.py",
|
||||
"/resources/bootstrap.css",
|
||||
"/resources/bootstrap.js",
|
||||
"/resources/pyscript.css",
|
||||
"/resources/pyscript.js",
|
||||
"/resources/pyscript.py",
|
||||
"/resources/pyscript_bootstrap_templates-0.1.0-py3-none-any.whl",
|
||||
"/resources/pwa.js",
|
||||
"/resourced/site.js",
|
||||
]
|
||||
self.addEventListener("install", installEvent => {
|
||||
installEvent.waitUntil(
|
||||
caches.open(pwa_version).then(cache => {
|
||||
cache.addAll(assets).then(r => {
|
||||
console.log("Cache assets downloaded");
|
||||
}).catch(err => console.log("Error caching item", err))
|
||||
console.log(`Cache ${pwa_version} opened.`);
|
||||
}).catch(err => console.log("Error opening cache", err))
|
||||
)
|
||||
})
|
||||
|
||||
self.addEventListener("fetch", fetchEvent => {
|
||||
fetchEvent.respondWith(
|
||||
caches.match(fetchEvent.request).then(res => {
|
||||
return res || fetch(fetchEvent.request)
|
||||
}).catch(err => console.log("Cache fetch error: ", err))
|
||||
)
|
||||
})
|
||||
|
2
examples/01_hello_world/resources/site.js
Normal file
2
examples/01_hello_world/resources/site.js
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
|
Reference in New Issue
Block a user