First get the project into the sample state by using the following commands:
$ git reset --hard
$ git checkout gif-response
Once the task is complete, enter the Task ID: gif-response
Take a look at the code located in public/js/sw/index.js
. As you can see, your task is to only respond with a .gif
if the request URL ends with .jpg
. How you determine that is up to you, but remember that event.request
gives you information about the request.
SOLUTION
self.addEventListener('fetch', function(event) {
if (event.request.url.endsWith('.jpg')) {
event.respondWith(
fetch('/imgs/dr-evil.gif')
);
}
});
Next: Hijacking Requests 3