Skip to content

Instantly share code, notes, and snippets.

@luke-denton-aligent
Last active November 16, 2016 04:02
Show Gist options
  • Save luke-denton-aligent/55f1174b4ed2067e832d5e55788fedc3 to your computer and use it in GitHub Desktop.
Save luke-denton-aligent/55f1174b4ed2067e832d5e55788fedc3 to your computer and use it in GitHub Desktop.
This snippet will show how to send a custom response to some requests, not all
// Offline Web Applications course on Udacity https://classroom.udacity.com/courses/ud899
//Using example from https://gist.github.com/luke-denton/2d0f00e76151d9e4bf412df8eb1bf354
// This example will replace all jpgs with superman.jpg
self.addEventListener('fetch', function(event) {
if (event.request.url.endsWith('.jpg')) {
event.respondWith(
//Any request made will receive a superman jpg as a response
fetch('/imgs/superman.jpg');
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment