Skip to content

Instantly share code, notes, and snippets.

@kmaraz
Created December 6, 2019 23:17
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 kmaraz/239aea696d297da0a533f8576232e731 to your computer and use it in GitHub Desktop.
Save kmaraz/239aea696d297da0a533f8576232e731 to your computer and use it in GitHub Desktop.
window.cacheUpdates = [];
window.channelInitialized = false;
export const initializeWorker = function() {
if ('BroadcastChannel' in window) {
// Subscribe to broadcast channel from worker
const apiUpdates = new BroadcastChannel(BROADCAST_CHANNEL);
apiUpdates.addEventListener('message', (event: any) => {
if (window.channelInitialized) {
return;
}
if (event.data.type === CACHE_UPDATED) {
const { cacheName, updatedURL } = event.data.payload;
console.log('W: worker append to cache updates', cacheName, updatedURL);
window.cacheUpdates.push({
cacheName, updatedURL
});
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment