diff options
author | altaf-creator <64111012+altaf-creator@users.noreply.github.com> | 2023-05-04 19:17:15 +0700 |
---|---|---|
committer | altaf-creator <64111012+altaf-creator@users.noreply.github.com> | 2023-05-04 19:17:15 +0700 |
commit | 1651ce848ac03ee867473d361c200ea863aef83f (patch) | |
tree | 9760791f47b61081e3dad3846c41f71b30f5fef2 /src/scripts | |
parent | 33c9622149c786a8d1c78b2da7dde5ca84c49529 (diff) |
PWA Update - attempt 1
Diffstat (limited to 'src/scripts')
-rw-r--r-- | src/scripts/main.js | 9 | ||||
-rw-r--r-- | src/scripts/service-worker.js | 41 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/scripts/main.js b/src/scripts/main.js new file mode 100644 index 0000000..e4efee0 --- /dev/null +++ b/src/scripts/main.js @@ -0,0 +1,9 @@ +if ("serviceWorker" in navigator) { + window.addEventListener("load", function () { + + navigator.serviceWorker + .register("scripts/service-worker.js") + .then(res => console.log("service worker registered")) + .catch(err => console.log("service worker not registered", err)) + }) +}
\ No newline at end of file diff --git a/src/scripts/service-worker.js b/src/scripts/service-worker.js new file mode 100644 index 0000000..30b921b --- /dev/null +++ b/src/scripts/service-worker.js @@ -0,0 +1,41 @@ +const staticQuran = "quran-all"; +const assets = [ + "/", + "/index.html", + "/src/index.html", + "/src/sura.html", + "/src/attribution.html", + "/src/styles/style.css", + "/src/styles/css/all.css", + "/src/styles/css/brands.css", + "/src/styles/css/solid.css", + "/src/styles/webfonts/fa-brands-400.ttf", + "/src/styles/webfonts/fa-brands-400.woff2", + "/src/styles/webfonts/fa-solid-900.ttf", + "/src/styles/webfonts/fa-solid-900.woff2", + "/src/styles/css/solid.css", + "/src/data/en.sahih.xml", + "/src/data/id.indonesian.xml", + "/src/data/quran-data.xml", + "/src/data/quran-uthmani.xml", + "/src/scripts/main.js", + "/src/scripts/quran.js", + "/src/scripts/sura-list.js", +]; + +self.addEventListener("install", installEvent => { + installEvent.waitUntil( + caches.open(staticQuran).then(cache => { + cache.addAll(assets) + console.log(assets) + }) + ) +}) + +self.addEventListener("fetch", fetchEvent => { + fetchEvent.respondWith( + caches.match(fetchEvent.request).then(res => { + return res || fetch(fetchEvent.request) + }) + ) +})
\ No newline at end of file |