Skip to content

Instantly share code, notes, and snippets.

@ahmetilhn
Last active May 2, 2024 18:55
Show Gist options
  • Save ahmetilhn/f866ff75e8dfa7ab1f224207413adb4c to your computer and use it in GitHub Desktop.
Save ahmetilhn/f866ff75e8dfa7ab1f224207413adb4c to your computer and use it in GitHub Desktop.
Service worker fetch listener (by ahmetilhn)
// self = context | window | provider
self.addEventListener('fetch', function(event) {
// İstek gitmeden önce yakalanır ve iptal edilir
event.respondWith(
fetch(event.request).then(response => {
// Burada response nesnesini özelleştirebilir veya değiştirebilirsiniz
return response;
}).catch(error => {
// Ağ hatası durumunda önbellekten bir kaynak döndürmek
return caches.match('/offline.html');
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment