Skip to content

Instantly share code, notes, and snippets.

@Danetag
Created January 7, 2018 21:37
Show Gist options
  • Save Danetag/6797f8046a42e41c36ce0689739ecf18 to your computer and use it in GitHub Desktop.
Save Danetag/6797f8046a42e41c36ce0689739ecf18 to your computer and use it in GitHub Desktop.
Part of service-worker
// On fetch
// ...
if (event.request.headers.get('accept').includes('text/html')) {
event.respondWith(toolbox.networkFirst(event.request));
return;
}
// ...
// Runtime cache configuration, using the sw-toolbox library.
toolbox.router.get(/^https:\/\/images\.contentful\.com/, toolbox.cacheFirst, {});
toolbox.router.get(/^https:\/\/images\.ctfassets\.net/, toolbox.cacheFirst, {});
toolbox.router.get(/^https:\/\/videos\.contentful\.com/, toolbox.cacheFirst, {});
toolbox.router.get(/^https:\/\/videos\.ctfassets\.net/, toolbox.cacheFirst, {});
toolbox.router.get(/^https:\/\/assets\.contentful\.com/, toolbox.cacheFirst, {});
toolbox.router.get(/^https:\/\/assets\.ctfassets\.net/, toolbox.cacheFirst, {});
toolbox.router.get(/^https:\/\/downloads\.contentful\.com/, toolbox.cacheFirst, {});
toolbox.router.get(/^https:\/\/downloads\.ctfassets\.net/, toolbox.cacheFirst, {});
toolbox.router.get(/^https:\/\/www\.chobani\.com/, toolbox.networkFirst, {});
toolbox.router.get(/^https:\/\/s3\.amazonaws\.com/, toolbox.fastest, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment