1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-06-21 15:04:01 +02:00

update talk.html

This commit is contained in:
Kushagra Gour
2025-05-03 13:18:56 +05:30
parent 8a2d18b403
commit b8179e9493

View File

@ -1,9 +1,5 @@
Hello
<script>
if (
'serviceWorker' in navigator
) {
if ('serviceWorker' in navigator) {
// Delay registration until after the page has loaded, to ensure that our
// precaching requests don't degrade the first visit experience.
// See https://developers.google.com/web/fundamentals/instant-and-offline/service-worker/registration
@ -11,17 +7,20 @@ Hello
navigator.serviceWorker
.register('service-worker.js')
.then(function (reg) {
// updatefound is fired if service-worker.js changes.
// Check for updates
reg.onupdatefound = function () {
// The updatefound event implies that reg.installing is set; see
// https://w3c.github.io/ServiceWorker/#service-worker-registration-updatefound-event
var installingWorker = reg.installing;
const installingWorker = reg.installing;
installingWorker.onstatechange = function () {
/* eslint-disable default-case */
switch (installingWorker.state) {
case 'installed':
console.log('New or updated content is available.', navigator.serviceWorker.controller);
if (navigator.serviceWorker.controller) {
// New content is available, refresh the page
window.location.reload();
} else {
console.log('Content is now available offline!');
}
break;
case 'redundant':
@ -38,20 +37,16 @@ Hello
});
});
}
</script>
<script>
console.log('controller', navigator.serviceWorker.controller)
window.addEventListener('message', (e) => {
console.log(88, e.data);
window.addEventListener('message', e => {
// console.log(88, e.data);
if (navigator.serviceWorker.controller) {
navigator.serviceWorker.controller.postMessage(e.data);
} else {
alert('Ooops, seems like your preview is denying updation. How about we slap a quick refresh on him?');
location.reload();
console.warn('Service worker not ready, reloading...');
window.location.reload();
}
});
</script>