-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "Start", | ||
"short_name": "Start", | ||
"theme_color": "#2196f3", | ||
"background_color": "#000000", | ||
"display": "standalone", | ||
"scope": "/", | ||
"start_url": "/", | ||
"orientation": "any", | ||
"icons": [ | ||
{ | ||
"src": "assets/icons/favicon.png", | ||
"sizes": "153x153" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
self.addEventListener("install", function (event) { | ||
event.waitUntil(preLoad()); | ||
}); | ||
|
||
var preLoad = function () { | ||
console.log("Installing web app"); | ||
return caches.open("offline").then(function (cache) { | ||
console.log("caching index and important routes"); | ||
return cache.addAll(["/", "/assets", "/offline.html"]); | ||
}); | ||
}; | ||
|
||
self.addEventListener("fetch", function (event) { | ||
event.respondWith( | ||
checkResponse(event.request).catch(function () { | ||
return returnFromCache(event.request); | ||
}) | ||
); | ||
event.waitUntil(addToCache(event.request)); | ||
}); | ||
|
||
var checkResponse = function (request) { | ||
return new Promise(function (fulfill, reject) { | ||
fetch(request).then(function (response) { | ||
if (response.status !== 404) { | ||
fulfill(response); | ||
} else { | ||
reject(); | ||
} | ||
}, reject); | ||
}); | ||
}; | ||
|
||
var addToCache = function (request) { | ||
return caches.open("offline").then(function (cache) { | ||
return fetch(request).then(function (response) { | ||
console.log(response.url + " was cached"); | ||
return cache.put(request, response); | ||
}); | ||
}); | ||
}; | ||
|
||
var returnFromCache = function (request) { | ||
return caches.open("offline").then(function (cache) { | ||
return cache.match(request).then(function (matching) { | ||
if (!matching || matching.status == 404) { | ||
return cache.match("offline.html"); | ||
} else { | ||
return matching; | ||
} | ||
}); | ||
}); | ||
}; |