UNPKG

sw2express

Version:

A lite & simple cross-platform Express-like web application framework

27 lines (26 loc) 734 B
<script> window.addEventListener("load", () => { if ("serviceWorker" in navigator) { navigator.serviceWorker .register("/sw.js", { scope: "/", }) .then((registration) => { console.info( `Service Worker registration successful with scope: ${registration.scope}` ); window.location.href = "/"; }) .catch((error) => console.warn(`Service Worker registration failed: ${error}`) ); } }); window.addEventListener("load", () => { if ("serviceWorker" in navigator) { navigator.serviceWorker.addEventListener("controllerchange", () => { window.location.reload(); }); } }); </script>