-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
9150b60
commit 86b6b9d
Showing
3 changed files
with
63 additions
and
42 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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
{ | ||
"name": "Text Editor", | ||
"short_name": "Text", | ||
"start_url": "texteditor.html", | ||
"display": "standalone", | ||
"description": "A Simple Text Editor", | ||
"start_url": "/", | ||
"lang": "en-US", | ||
"theme_color": "cornflowerblue", | ||
"background_color": "lightblue", | ||
"orientation": "portrait-primary", | ||
"display": "standalone", | ||
"icons": [ | ||
{ | ||
"src": "/texteditor.png", | ||
"type": "image/png", "sizes": "72x72" | ||
} | ||
{ | ||
"src": "texteditor.png", | ||
"sizes": "72x72", | ||
"type": "image/png" | ||
} | ||
] | ||
} | ||
} |
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 |
---|---|---|
@@ -1,21 +1,36 @@ | ||
const staticDevCoffee = "dev-coffee-site-v1"; | ||
const assets = [ | ||
"/texteditor.html", | ||
"/texteditor.png" | ||
]; | ||
const CACHE_NAME = `simple-texteditor`; | ||
|
||
self.addEventListener("install", installEvent => { | ||
installEvent.waitUntil( | ||
caches.open(staticDevCoffee).then(cache => { | ||
cache.addAll(assets) | ||
}) | ||
) | ||
// Use the install event to pre-cache all initial resources. | ||
self.addEventListener('install', event => { | ||
event.waitUntil((async () => { | ||
const cache = await caches.open(CACHE_NAME); | ||
cache.addAll([ | ||
'/', | ||
'/texteditor.html', | ||
'/texteditor.png' | ||
]); | ||
})()); | ||
}); | ||
|
||
self.addEventListener("fetch", fetchEvent => { | ||
fetchEvent.respondWith( | ||
caches.match(fetchEvent.request).then(res => { | ||
return res || fetch(fetchEvent.request) | ||
}) | ||
) | ||
self.addEventListener('fetch', event => { | ||
event.respondWith((async () => { | ||
const cache = await caches.open(CACHE_NAME); | ||
|
||
// Get the resource from the cache. | ||
const cachedResponse = await cache.match(event.request); | ||
if (cachedResponse) { | ||
return cachedResponse; | ||
} else { | ||
try { | ||
// If the resource was not in the cache, try the network. | ||
const fetchResponse = await fetch(event.request); | ||
|
||
// Save the resource in the cache and return it. | ||
cache.put(event.request, fetchResponse.clone()); | ||
return fetchResponse; | ||
} catch (e) { | ||
// The network failed. | ||
} | ||
} | ||
})()); | ||
}); |