Last active
January 15, 2016 20:21
-
-
Save jakearchibald/8d9a6100c47521b5ed88 to your computer and use it in GitHub Desktop.
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
<!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> |
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
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