Skip to content

Instantly share code, notes, and snippets.

@reedjones
Last active October 12, 2024 16:50
Show Gist options
  • Save reedjones/8176e9444fd06741803c21730b24ffd4 to your computer and use it in GitHub Desktop.
Save reedjones/8176e9444fd06741803c21730b24ffd4 to your computer and use it in GitHub Desktop.
Javascript Code Snippets

Javascript Code Snippets

hello

asdf

cache-refresh-stratedgy

self.addEventListener('fetch', function(evt) {
  evt.respondWith(fromCache(evt.request));
  evt.waitUntil(
    update(evt.request)
    .then(refresh)
  );
});

function refresh(response) {
  return self.clients.matchAll().then(function (clients) {
    clients.forEach(function (client) {
      var message = {
        type: 'refresh',
        url: response.url,
        eTag: response.headers.get('ETag')
      };
      client.postMessage(JSON.stringify(message));
    });
  });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment