summaryrefslogtreecommitdiff
path: root/src/scripts
diff options
context:
space:
mode:
authoraltaf-creator <64111012+altaf-creator@users.noreply.github.com>2023-05-04 21:26:41 +0700
committeraltaf-creator <64111012+altaf-creator@users.noreply.github.com>2023-05-04 21:26:41 +0700
commit5725accf76d1ec02d569c59a9989b7d72827a7ee (patch)
tree8f878ab186fdc67216c6b001d3993bfbb7e510f1 /src/scripts
parentf45d7e0c18fb2254a1362e1b9d34047d50251765 (diff)
PWA Update - attempt 5.2
Diffstat (limited to 'src/scripts')
-rw-r--r--src/scripts/service-worker.js46
1 files changed, 42 insertions, 4 deletions
diff --git a/src/scripts/service-worker.js b/src/scripts/service-worker.js
index 2911784..19f58b8 100644
--- a/src/scripts/service-worker.js
+++ b/src/scripts/service-worker.js
@@ -22,12 +22,11 @@ const assets = [
"../src/scripts/quran.js",
"../src/scripts/sura-list.js",
];
-
+/*
self.addEventListener("install", installEvent => {
installEvent.waitUntil(
caches.open(staticQuran).then(cache => {
- for (var i = 0; i < assets.length; i++)
- {
+ for (var i = 0; i < assets.length; i++) {
cache.add(assets[i]);
}
})
@@ -40,4 +39,43 @@ self.addEventListener("fetch", fetchEvent => {
return res || fetch(fetchEvent.request);
})
)
-}) \ No newline at end of file
+})
+*/
+
+self.addEventListener('install', function (event) {
+ console.log('Service worker installed');
+
+ event.waitUntil(
+ caches.open('staticQuran')
+ .then(function (cache) {
+ console.log('Cache opened');
+ return cache.addAll(assets);
+ })
+ .then(function () {
+ console.log('Assets cached');
+ })
+ .catch(function (error) {
+ console.error('Error caching assets:', error);
+ })
+ );
+});
+
+self.addEventListener('fetch', function (event) {
+ console.log('Fetch event:', event.request.url);
+
+ event.respondWith(
+ caches.match(event.request)
+ .then(function (response) {
+ if (response) {
+ console.log('Cached response found:', response);
+ return response;
+ }
+
+ console.log('No cached response found, fetching from network');
+ return fetch(event.request);
+ })
+ .catch(function (error) {
+ console.error('Error fetching from cache:', error);
+ })
+ );
+}); \ No newline at end of file