Created
July 19, 2020 13:37
-
-
Save RReverser/4727d46ba133d9471f51355ae505d097 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
addEventListener('fetch', event => { | |
if (event.request.method === 'PUT') { | |
event.respondWith(handleRequest(event)); | |
} | |
}); | |
async function handleRequest(event) { | |
let response = await fetch(event.request); | |
if (!response.ok) return response; | |
let urls = ['/']; | |
try { | |
let json = await response.clone().json(); | |
urls = urls.concat(json.posts.map(post => post.url)); | |
event.waitUntil(Promise.allSettled( | |
urls.map(url => caches.default.delete(`https://rreverser.com${url}`)) | |
)); | |
} finally { | |
return response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment