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
const updateChannel = new BroadcastChannel('precache-channel'); | |
updateChannel.addEventListener('message', event => { | |
if (confirm(`New content is available!. Click OK to refresh`)) { | |
window.location.reload(); | |
} | |
}); |
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
workbox.precaching.addPlugins([ | |
new workbox.broadcastUpdate.Plugin('precache-channel') | |
]) |
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
addEventListener('backgroundfetchfail', event => { | |
console.log('[Service Worker]: Background Fetch Fail', event.registration); | |
event.waitUntil( | |
(async function() { | |
try { | |
const cache = await caches.open(event.registration.id); | |
const records = await event.registration.matchAll(); | |
const promises = records.map(async record => { | |
const response = await record.responseReady | |
if (response && response.ok) { |
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
<button id="bgFetchButton">Store assets locally</button> | |
<div id="progressStatus">Progress: waiting...</div> | |
<script> | |
bgFetchButton = document.querySelector('#bgFetchButton'); | |
progressStatus = document.querySelector('#progressStatus'); | |
bgFetchButton.addEventListener('click', async event => { | |
// Let's assume that we got some unique ID of the asset set we want to download | |
let assetToFetchId = 'series'; |
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
<script> | |
bgFetchButton.addEventListener('click', async event => { | |
try { | |
event.target.disabled = true; | |
const registration = await navigator.serviceWorker.ready; | |
registration.backgroundFetch.fetch('my-fetch', [ | |
'/assets/s01e01.mpg', | |
'/assets/s01e02.mpg' |
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
$ http-server | |
Starting up http-server, serving ./ | |
Available on: | |
http://127.0.0.1:8084 | |
http://172.16.110.136:8084 |
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
<button id="bgFetchButton">Store assets locally</button> | |
<script> | |
bgFetchButton = document.querySelector('#bgFetchButton'); | |
bgFetchButton.addEventListener('click', async event => { | |
try { | |
const registration = await navigator.serviceWorker.ready; | |
registration.backgroundFetch.fetch('my-fetch', ['/assets/s01e01.mpg']); | |
} catch (err) { | |
console.error(err); |
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
addEventListener('fetch', event => { | |
// Do nothing | |
}); |
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
var authentication = "key=...&token=..."; | |
var idBoard = "..."; | |
var inboxList = "..."; | |
var updatedLabel = "..."; | |
var travelLabel = "..."; | |
// To process all current records - run sendAll() | |
// To set up a trigger for the new records - run init() | |
function init() { |
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
checkForUpdate() { | |
console.log('[App] checkForUpdate started') | |
this.swUpdate.checkForUpdate() | |
.then(() => { | |
console.log('[App] checkForUpdate completed') | |
}) | |
.catch(err => { | |
console.error(err); | |
}) | |
} |