Skip to content

Instantly share code, notes, and snippets.



Last active Jan 15, 2016
What would you like to do?
<!doctype html>
navigator.serviceWorker.addEventListener('controllerchange', () => window.location.reload());
if (navigator.serviceWorker.controller) {
var req = new XMLHttpRequest();'GET', 'xhr');
req.onload = function() {
console.log('XHR loaded', req.responseText);
// Handle network errors
req.onerror = function() {
console.log('XHR error');
// Make the request
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.