Last active
April 11, 2018 15:47
-
-
Save monkindey/7d938e82cdbdeee4b590e792f0755613 to your computer and use it in GitHub Desktop.
Service worker get config from outside
This file contains hidden or 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
if ('serviceWorker' in navigator) { | |
navigator.serviceWorker | |
.register('./sw.js') | |
.then(function(registration) { | |
const interval = setInterval(() => { | |
try { | |
registration.installing.postMessage({ | |
'api.github.com/users/monkindey': {} | |
}); | |
} catch (err) { | |
clearInterval(interval); | |
} | |
}, 500); | |
console.log('Service worker registration succeeded:', registration); | |
}) | |
.catch(function(error) { | |
console.log('Service worker registration failed:', error); | |
}); | |
} else { | |
console.log('Service workers are not supported.'); | |
} | |
axios.get('https://api.github.com/users/monkindey').then(res => { | |
console.log(res); | |
}); | |
window.onload = () => { | |
axios.get('https://api.github.com/users/monkindey').then(res => { | |
console.log(res); | |
}); | |
}; |
This file contains hidden or 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
let fetchings = null; | |
const installPromise = new Promise(function(resolve, reject) { | |
self.addEventListener('message', function(event) { | |
fetchings = event.data; | |
resolve(); | |
}); | |
}); | |
self.addEventListener('install', event => { | |
console.log('install'); | |
event.waitUntil(installPromise); | |
}); | |
self.addEventListener('fetch', event => { | |
console.log(fetchings, event.request.url); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment