-
-
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.
Merge pull request #25 from sombriks/develop
ading service worker
- Loading branch information
Showing
3 changed files
with
56 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<link rel="icon" href="/favicon.ico"> | ||
<link rel="manifest" href="/manifest.json"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1,maximum-scale=2.0"> | ||
<title>Redline Finance</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.js"></script> | ||
</body> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<link rel="icon" href="/favicon.ico"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1,maximum-scale=2.0"> | ||
<title>Redline Finance</title> | ||
<link rel="manifest" href="/manifest.json"> | ||
<script type="application/javascript"> | ||
if ('serviceWorker' in navigator) navigator.serviceWorker.register('sw.js') | ||
</script> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.js"></script> | ||
</body> | ||
</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 |
---|---|---|
|
@@ -40,5 +40,8 @@ | |
], | ||
"share_target": { | ||
"method": "GET" | ||
}, | ||
"edge_side_panel": { | ||
"preferred_width": 360 | ||
} | ||
} |
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,39 @@ | ||
// https://docs.pwabuilder.com/#/home/sw-intro?id=example-worker | ||
|
||
const CACHE_NAME = 'cool-cache'; | ||
|
||
// Add whichever assets you want to pre-cache here: | ||
const PRECACHE_ASSETS = [ | ||
'/assets/', | ||
'/dados.csv' | ||
] | ||
|
||
// Listener for the install event - pre-caches our assets list on service worker install. | ||
self.addEventListener('install', event => { | ||
event.waitUntil((async () => { | ||
const cache = await caches.open(CACHE_NAME); | ||
cache.addAll(PRECACHE_ASSETS); | ||
})()); | ||
}); | ||
|
||
self.addEventListener('activate', event => { | ||
event.waitUntil(self.clients.claim()); | ||
}); | ||
|
||
self.addEventListener('fetch', event => { | ||
event.respondWith(async () => { | ||
const cache = await caches.open(CACHE_NAME); | ||
|
||
// match the request to our cache | ||
const cachedResponse = await cache.match(event.request); | ||
|
||
// check if we got a valid response | ||
if (cachedResponse !== undefined) { | ||
// Cache hit, return the resource | ||
return cachedResponse; | ||
} else { | ||
// Otherwise, go to the network | ||
return fetch(event.request) | ||
}; | ||
}); | ||
}); |