improved pwa functionality

This commit is contained in:
2022-10-16 12:54:39 +02:00
parent 3dc051aba1
commit 4ca2cdff70
22 changed files with 56336 additions and 174 deletions

View File

@ -3,9 +3,9 @@
"title": "01_hello_world",
"packages": [],
"paths": [],
"pyscript_css_url": "https://pyscript.net/alpha/pyscript.css",
"pyscript_js_url": "https://pyscript.net/alpha/pyscript.min.js",
"pyscript_py_url": "https://pyscript.net/alpha/pyscript.py",
"pyscript_css_url": "https://pyscript.net/latest/pyscript.css",
"pyscript_js_url": "https://pyscript.net/latest/pyscript.js",
"pyscript_py_url": "https://pyscript.net/latest/pyscript.py",
"bootstrap_css_url": "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css",
"bootstrap_js_url": "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js",
"pyscript_bootstrap_templates_wheel_url": "../dist/pyscript_bootstrap_templates-0.1.0-py3-none-any.whl",

View File

@ -7,26 +7,29 @@
<link rel="manifest" href="manifest.json" />
<script src="./resources/pwa.js"></script>
<link rel="stylesheet" href="./resources/pyscript.css" />
<script defer src="./resources/pyscript.js"></script>
<!-- Bootstrap CSS -->
<link href="./resources/bootstrap.css" rel="stylesheet">
<title>01_hello_world</title>
<py-env>
- ./resources/pyscript_bootstrap_templates-0.1.0-py3-none-any.whl
- paths:
</py-env>
</head>
<body style="width: 100%; height: 100%">
<py-config type="json">
{
"autoclose_loader": true,
"packages": [
"./resources/pyscript_bootstrap_templates-0.1.0-py3-none-any.whl"
],
"paths": []
}
</py-config>
<div id="pyscript_app" style="height: 100%; min-height: 100%"></div>
<py-script src="./main.py"></py-script>
<script src="./resources/bootstrap.js"></script>
<script src="./resources/pwa.js"></script>
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,32 +0,0 @@
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))
)
})

View File

@ -1,2 +0,0 @@

View File

@ -1,5 +1,5 @@
const pwa_version = "202210160804"
const pwa_version = "01_hello_world_202210161053"
const assets = ["./index.html",
"./main.py",
"./resources/bootstrap.css",
@ -22,11 +22,30 @@ self.addEventListener("install", installEvent => {
)
})
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))
)
})
self.addEventListener('activate', e => {
console.log('Service Worker: Activated');
});
self.addEventListener('fetch', event => {
if (event.request.method != 'GET')
return;
event.respondWith((async () => {
const cachedResponse = await caches.match(event.request);
if (cachedResponse) {
return cachedResponse;
}
const response = await fetch(event.request);
if (!response || response.status !== 200 || response.type !== 'basic') {
return response;
}
const responseToCache = response.clone();
const cache = await caches.open(pwa_version)
await cache.put(event.request, response.clone());
return response;
})());
});