Skip to content

Instantly share code, notes, and snippets.

@MattIPv4
Created June 6, 2019 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattIPv4/1371cac248d763ab93fc5c13056cef96 to your computer and use it in GitHub Desktop.
Save MattIPv4/1371cac248d763ab93fc5c13056cef96 to your computer and use it in GitHub Desktop.
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request))
})
async function fetchAndApply(request) {
const requestURL = new URL(request.url)
if(!requestURL.pathname.startsWith('/ajax/libs')) {
requestURL.pathname = '/ajax/libs' + requestURL.pathname
const newResponse = await fetch(requestURL, request)
if(newResponse.status == 200) return newResponse
}
return fetch(request)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment