<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
/>
<
meta
name
=
"viewport"
content
=
"width=device-width, initial-scale=1.0"
/>
<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"ie=edge"
/>
<
link
rel
=
"stylesheet"
href
=
"./style.css"
/>
<
title
>Service Worker App</
title
>
</
head
>
<
body
>
<
div
class
=
"wrapper"
>
<
img
src
=
alt
=
"GfG logo"
/>
<
button
type
=
"button"
onClick
=
"window.location.reload();"
>
Refresh Page
</
button
>
</
div
>
<
script
>
// Check if browser supports service workers
if (navigator.serviceWorker) {
console.log("Service Worker Supported");
// Start registration process on page load
window.addEventListener("load", () => {
navigator.serviceWorker
// The register function takes as argument
// the file path to the worker's file
.register("./service_worker.js")
// Gives us registration object
.then(reg => console.log("Service Worker Registered"))
.catch(swErr => console.log(
`Service Worker Error: ${swErr}}`));
});
}
</
script
>
</
body
>
</
html
>