Skip to content

Instantly share code, notes, and snippets.

@petebrowne
Created February 19, 2016 23:53
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 petebrowne/3754410110d3e3f75668 to your computer and use it in GitHub Desktop.
Save petebrowne/3754410110d3e3f75668 to your computer and use it in GitHub Desktop.
function isHtmlRequest(request) {
return (
request.method === 'GET' &&
request.headers.get('accept').includes('text/html')
);
}
self.addEventListener('fetch', event => {
if (isHtmlRequest(event.request)) {
event.respondWith(
fetch(event.request).catch(() => {
return caches.match(OFFLINE_URL);
})
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment