JS

OFFLINE WEB APP WITH JAVASCRIPT

IN THE <HEAD> SECTION <script> navigator.serviceWorker.register ("WORKER.JS"); </script>

HTML REGISTER SERVICE WORKER

01

FILES TO CACHE const cName = "HelloOffline", cFiles = ["MAIN.HTML", "YOUR.JS"];

SERVICE WORKER (A)

02

CREATE/INSTALL CACHE self.addEventListener("install", (evt) => {   evt.waitUntil(     caches.open(cName).then((cache) =>     { return cache.addAll(cFiles); })   ); });

SERVICE WORKER (B)

03

LOAD FROM CACHE, FALLBACK TO NETWORK IF NOT FOUND self.addEventListener("fetch", (evt) => {   evt.respondWith(     caches.match(evt.request)     .then((res) => { return res ||      fetch(evt.request); })   ); });