Skip to content

Instantly share code, notes, and snippets.

@jakearchibald jakearchibald/index.html
Last active Jan 15, 2016

Embed
What would you like to do?
<!doctype html>
<script>
navigator.serviceWorker.addEventListener('controllerchange', () => window.location.reload());
navigator.serviceWorker.register('sw.js');
if (navigator.serviceWorker.controller) {
var req = new XMLHttpRequest();
req.open('GET', 'xhr');
req.onload = function() {
console.log('XHR loaded', req.responseText);
};
// Handle network errors
req.onerror = function() {
console.log('XHR error');
};
// Make the request
req.send();
}
</script>
self.addEventListener('activate', () => clients.claim());
self.addEventListener('fetch', event => {
if (event.request.url.endsWith('xhr')) {
event.respondWith(new Response('This is from the service worker'));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.