Last active
November 29, 2022 01:48
-
-
Save noamr/c9efc56220820d5dd716eb6f64c11146 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", e => { | |
if (e.request.destination !== "image" || // Only do this when requesting an image | |
request.mode === "no-cors") // We don't know the status of no-cors images | |
return; | |
e.respondWith((async () => { | |
try { | |
const response = await fetch(e.request); | |
if (response.ok) | |
return response; | |
} catch { | |
} | |
return Response.redirect("/your/fallback/url.svg"); | |
})()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment